I have a javascript that goes trough a html table with fixed columns and different rows and assign the values from the textboxes to variables where one is an array. For every row I want to insert the values into a mysql table. For test purpose I create a small table call “teste” with a field call “nome”. Whenever the checkForm is called from a button it inserts the a new register under the table “teste” but the field “nome” is empty. Can anyone help me on this? Regards, Joaquim
<script type="text/javascript">
function checkForm()
{
var tabela = document.getElementById("t02")
var c=tabela.rows.length;
var cnt=0;
var arr = new Array(12);
for(var i=2; i<=c-1; i++)
{
cnt++;
soc=document.getElementById("sc"+cnt).innerHTML;
arr[0]=document.getElementById("st"+cnt).value;
arr[1]=document.getElementById("ot"+cnt).value;
arr[2]=document.getElementById("nv"+cnt).value;
arr[3]=document.getElementById("dz"+cnt).value;
arr[4]=document.getElementById("ja"+cnt).value;
arr[5]=document.getElementById("fv"+cnt).value;
arr[6]=document.getElementById("mr"+cnt).value;
arr[7]=document.getElementById("ab"+cnt).value;
arr[8]=document.getElementById("mi"+cnt).value;
arr[9]=document.getElementById("ju"+cnt).value;
arr[10]=document.getElementById("jl"+cnt).value;
arr[11]=document.getElementById("obs"+cnt).value;
for(var a =0; a<=11; a++)
{
if(!arr[a]=="")
{
//alert(soc);
var nom = new XMLHttpRequest();
nom.open("POST","gravaMensalidade.php",true);
nom.onreadystatechange = function()
{
if( this.readyState != 4) return;
if( this.status != 200) return alert("ERROR
"+this.status+" "+this.statusText);
alert(this.responseText);
};
nom.send("nome="+soc);
}
}
}
}
</script>
<?php
/*
* To change this license header, choose License Headers in Project
Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
include 'ligabd.php';
$query="INSERT INTO TESTE(nome) VALUES('".$_POST['nome']."')";
$res=mysqli_query($l, $query);
?>