$.ajax({
url: 'http://localhost/xampp/htdocs/ajax.php',
contentType: 'application/json',
type: 'post',
data: {
//score is a new variable and count2 is an integer variable which i want to send it to the database "score":"count2" },
success: function () {
alert("ok");
},
error: function () {
alert("error");
}
});
The above code alerts me "ok".
function connect(){
$connect = mysql_connect('localhost','root','') or die("ERROR");
$connect2Database = mysql_select_db('fypdb', $connect);
return $connect;
}
if(isset($_POST)){
if($connect = connect()){
$query = "INSERT INTO fypdbtable (score) VALUES ('".$_POST['score']."');";
$completeQuery = mysql_query($query, $connect);
}
}
I think the problem is on "insert into" query because in ajax.php prompts me Notice: Undefined index: score in C:\xampp\htdocs\xampp\htdocs\ajax.php on line 14 where it is the query line
Any help would be appreciate
The "error" message tells you, that $_POST['score'] is not defined. But thats just a warning. If you want to know if your variable is set, use isset() function or turn off warnings in the configuration.