Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

162
Views
Insert javascript variables into databasw

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?

about 4 years ago · Juan Pablo Isaza
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!