I want to send JS variables using Ajax, to a PHP page so that I could save those variable in the Database. However, it isn't working as I expected. My JS code:
var a= payment;
var b= count_days;
var c= <?php echo $teacher_id; ?>;
var jsonString1 = JSON.stringify(a);
var jsonString2= JSON.stringify(b);
var jsonString3= JSON.stringify(c);
$.ajax({
type: "POST",
url: "student_searching_availibility.php",
data: {
data1 : jsonString1,
data2:jsonString2,
data3:jsonString3
},
cache: false,
success: function() {
alert('success');
}
});
Now my PHP
$data1 = json_decode($_POST['data1']);
$data2 = json_decode($_POST['data2']);
$data3 = json_decode($_POST['data3']);
include "db.php";
$sql2= "INSERT INTO availibility_status_date(student_id,teacher_id,status) VALUES ('$data1','$data2','$data3')";
if(!mysqli_query($con,$sql2)){
die("error". mysqli_connect_error());
}
I have searched almost all such queries here but still could not solve the problem.
$_POST? Prepare the necessary code on the student_searching_availibility.php side, reload your submission page, open Inspect inside your browser > Network tab and watch what you receive.