Hey guys, I have this piece of jquery code:
<script type="text/javascript" >
$(function() {
$(".submitButton").click(function() {
var post = $("#post").val();
var dataString = 'post='+ post;
if(post=='')
{
$('.error').fadeIn(200).show();
}
else
{
$.ajax({
type: "POST",
url: "post.php",
data: dataString,
success: function(){
$('.error').fadeOut(200).hide();
}
});
}
return false;
});
$('.error').hide();
});
</script>
And I want it to post the values without refreshing. I created post.php:
<?php
ini_set('display_errors', 'On');
error_reporting(E_ALL);
session_start();
$post=mysql_real_escape_string($_POST['post']);
$mysql=mysql_connect('localhost','***','***');
mysql_select_db('jmtdy');
$result=mysql_query("select * from users where username='".$_SESSION['username']."'") or die(mysql_error());
$dbarray=mysql_fetch_assoc($result);
mysql_query("insert into posts (userid, post, username) values ('".$dbarray['id']."','".$post."','".$dbarray['username']."'") or die(mysql_error());
?>
But the values are still not being added to the database. Do you know what the problem might be?
Have you checked to make sure that the server isn’t throwing an error somewhere? You should check to make sure your PHP script runs correctly by outputting something.
I would also recommend using Firebug (or Chrome Dev. Tools) to monitor XHR requests and see if there are any issues there.