Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

159
Vistas
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
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda