Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

My Ajax call does not submit to php

Tags:

ajax

php

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.

like image 651
Tim Zhukov-Khovanskiy Avatar asked Feb 17 '26 14:02

Tim Zhukov-Khovanskiy


1 Answers

mysql_query("INSERT INTO tracking ( username, lessonid ) VALUES ('".$username."', ".$lessonid." );");

You missed quotes in that line. Also, please read about SQL Injection.

like image 190
rationalboss Avatar answered Feb 20 '26 04:02

rationalboss



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!