otester Posted August 3, 2010 Share Posted August 3, 2010 I am currently trying to implement Ajax into a new chat function, however in the database under messages it keeps showing up as: [object HTMLInputElement] but the date (CURRENT_TIMESTAMP) works fine. Why does it do this? Here is the main code for the page: <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>Untitled Document</title> <script type="text/javascript" src="jquery-1.4.js"></script> <script type="text/javascript"> $(document).ready(function(){ $("form#submit").submit(function() { // we want to store the values from the form input box, then send via ajax below var fname = $('#Messages').attr('value'); $.ajax({ type: "POST", url: "ajax2.php", data: "Messages="+ Messages, success: function(){ $('form#submit').hide(function(){$('div.success').fadeIn();}); } }); return false; }); }); </script> </head> <body> <div class="container"> <form id="submit" method="post"> <fieldset> <legend>Enter Information</legend> <label for="Messages">Message:</label> <input id="Messages" class="text" name="Messages" size="20" type="text"> <button class="button positive">Submit comment!</button> </fieldset> </form> <div class="success" style="display:none;">Comment has been added.</div> </div> </body> </html> Ajax2.php file: <?php $con = mysql_connect("x","x","x"); if (!$con) { die('Could not connect: ' . mysql_error()); } mysql_select_db("x", $con); // CLIENT INFORMATION $Messages = htmlspecialchars(trim($_POST['Messages'])); $addClient = "INSERT INTO Comments (Messages,Date) VALUES ('$Messages', CURRENT_TIMESTAMP)"; mysql_query($addClient) or die(mysql_error()); ?> Any help would be greatly appreciated, Thanks, otester Quote Link to comment Share on other sites More sharing options...
ToonMariner Posted August 3, 2010 Share Posted August 3, 2010 replace your jquery with this: $(document).ready(function(){ $("form#submit").submit(function() { // we want to store the values from the form input box, then send via ajax below var mssg = $('#Messages').val(); $.ajax({ type: "POST", url: "ajax2.php", data: "Messages="+ mssg, success: function(){ $('form#submit').hide(function(){$('div.success').fadeIn();}); } }); return false; }); }); Quote Link to comment Share on other sites More sharing options...
otester Posted August 3, 2010 Author Share Posted August 3, 2010 replace your jquery with this: $(document).ready(function(){ $("form#submit").submit(function() { // we want to store the values from the form input box, then send via ajax below var mssg = $('#Messages').val(); $.ajax({ type: "POST", url: "ajax2.php", data: "Messages="+ mssg, success: function(){ $('form#submit').hide(function(){$('div.success').fadeIn();}); } }); return false; }); }); I see that I forgot to replace fname with Messages, thanks for your help! Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.