I have this function in javascript
function addRow( i , name , first , second , final , partic , abc , Grade){
names[i] = name;
fiM[i] = first;
secM[i] = second;
finalM[i] = final;
parti[i] = partic;
Y_N[i] = ABC;
grades[i] = Grade;
}
I want to insert the parameters of this function into a database using php I tried to solve this problem using ajax but I think I didn't used it correctly
I tried this code:
function addRow( i , name , first , second , final , partic , abc , Grade){
computeBtn.addEventListener("click", (e) => {
let xmlhttp = new XMLHttpRequest();
xmlhttp.open(
"GET",
"addStudent.php?first=" +
first+
"&second=" +
second +
"&final=" +
final +
"&prt=" +
partic+
"&abc = " +
abc +
"&name = " +
name+
"&grade = " +grade
,
true
);
xmlhttp.send();
xmlhttp.onstatechange = function () {
console.log(xmlhttp.response);
};
});
names[i] = name ;
fiM[i] = first ;
secM[i] = second ;
finalM[i] = final ;
parti[i] = partic ;
Y_N[i] = abc ;
grades[i] = Grade ;
}
and in php file
<?php
$con = mysqli_connect("localhost", "root","12345678", "advanceweb");
$name = $_GET['name'];
$first = $_GET['first'];
$second = $_GET['second'];
$final = $_GET['final'];
$prt = $_GET['prt'];
$abs = $_GET['abc'];
$g = $_GET['grade'];
$q_insert = "INSERT INTO `newstudent` (`StudentName`, `first`, `second`, `final`, `partcipation`, `Absences`, `grade`) VALUES ('$name','$first','$second','$final','$prt','$abs','$g')";
mysqli_query($con, $q_insert);
mysqli_close($con);?>
Can anyone help me to correct it please?