Good afternoon, dear experts! Unfortunately, I don’t know much about programming and please help. I have a feedback form on the site, ajax + php, I also added the entry of the entered values into the SQL database, but sometimes the values come empty, although all the required fields, in the SQL database, empty records also sometimes appear. I can not localize the problem, how many times I did not try to send letters - everything is ok.
Here is my code
<form action="javascript:void(null);" id="form" class="form" name="FORM"> <input type="text" name="contact" required="required" id="input1" class="input" placeholder="E-mail или телефон" maxlength="30"> <textarea type="text" name="question" required="required" id="input2" class="input" placeholder="Напишите Ваш вопрос" maxlength="300"></textarea> <input type="submit" class="btn btn-success" value="Отправить"> </form> $(document).ready(function () { $("#form").submit(function () { //устанавливаем событие отправки для формы с id=form var form_data = $(this).serialize(); //собераем все данные из формы $.ajax({ type: "POST", //Метод отправки url: "php/mail.php", //путь до php фаила отправителя data: form_data, success: function () { //код в этом блоке выполняется при успешной отправке сообщения alert("Спасибо! Ответим, как только сможем :)"); show('none'); }, error: function (xhr, str) { alert('Error: ' + xhr.responseCode); } }); }); }); <? [![введите сюда описание изображения][1]][1]require 'c.php'; var_dump($_POST); { //Проверка отправилось ли наше поля $to = 'example@mail.ru'; //Почта получателя, через запятую можно указать сколько угодно адресов $subject = 'Обратный звонок'; //Загаловок сообщения $message = ' <html> <head><meta http-equiv="Content-Type" content="text/html; charset=utf8"> <title>'.$subject.'</title> </head> <body> <p>'.$_POST['contact'].'</p> <p>'.$_POST['question'].'</p> </body> </html>'; //Текст нащего сообщения можно использовать HTML теги $headers = "Content-type: text/html; charset=utf8 \r\n"; //Кодировка письма $headers .= "From: <contact@example.ru>\r\n"; //Наименование и почта отправителя mail($to, $subject, $message, $headers); //Отправка письма с помощью функции mail }; //соединение с базой $result = "INSERT INTO clients (mail) values('$contact')"; mysql_query($result); mysql_close($mysql); ?> I will attach two examples that SOMETIMES arrive in the mail and entered into the SQL database. Wiped addresses from detractors :)
Проверка отправилось ли наше поля? - lolbas