Following snippet should be collecting data and sending it to a php file. It does output proper values on click of the button.
var dataString = 'username='+SessionVars.my_username+'&lessonid='+SessionVars.my_lesson_number;
$('#tracking_submit').click(function(){
$.ajax({
url: "php/tracking.php",
type:'POST',
data: dataString,
success: function(){
$('#tracking_message').replaceWith(SessionVars.my_username+"Thank you for updating."+SessionVars.my_lesson_number);
}
});
return false;
});
Then the php file portion i'm using is this:
session_start();
mysql_connect("stuff i tested and it works");
mysql_select_db("same");
$username=$_POST['username'];
$lessonid=$_POST['lessonid'];
mysql_query("INSERT INTO tracking ( username, lessonid ) VALUES ( ".$username.", ".$lessonid." );");
When I check the database, there is nothing in it.
mysql_query("INSERT INTO tracking ( username, lessonid ) VALUES ('".$username."', ".$lessonid." );");
You missed quotes in that line. Also, please read about SQL Injection.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With