There is a simple chat on php / ajax / mysql. But unfortunately, when you submit a form, an empty string is entered into the database. What could be the problem?

Here is the file with the form, page.php:

<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>Document</title> <script src="http://ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js"></script> <script> $(document).ready(function(){ $("#messages").load('ajaxLoad.php'); $("#userArea").submit(function(){ $.post('ajaxPost.php', $('#userArea').serialize(), function(data){ $("#messages").append('<div>'+data+'</div>'); }); return false; }); }); </script> <body> <div class="container"> <div id="messages"></div> <form method="post" action="ajaxPost.php" id="userArea" style="margin: 0 auto; font-size: 23px; text-align: center;"> <h1>Чат</h1> <input type="text" name="message" /> <input type="submit" value="ответить !" /> </form> </div> <?php include_once('ajaxLoad.php'); ?> <?php include_once('ajaxPost.php'); ?> 

The file that works with the form ajaxPost.php:

 <?php include_once('page.php'); include('config.php'); $message = $_POST['message']; $db->Query("INSERT INTO messages(message1) VALUES ('$message')"); echo $message; ?> 
  • Does a message appear in the house after append? - splash58
  • Yes. An empty <div> appears. And a new cell with id is entered into the base, but with an empty 'message' field. - Bim Bam
  • one
    but look through the alert that you have in $ ('# userArea'). serialize () before sending - splash58
  • miracles and only - splash58
  • Oh. This is if the checkbox. But if the text, then: message = 123 where 123 is the entered text. - Bim Bam

0