I'm working with this project and I need to pass an array as an URL parameter and I actually manage to do it with javascript.
function guardarTodo()
{
var datos = [];
var txtfechaCap = document.getElementById("txtfechaCap").value;
datos.push(txtfechaCap);
var cbxLocalidad = document.getElementById("cbxLocalidad").value;
datos.push(cbxLocalidad);
var txtapellidoP = document.getElementById("txtapellidoP").value;
datos.push(txtapellidoP);
var txtapellidoM = document.getElementById("txtapellidoM").value;
datos.push(txtapellidoM);
var txtNombres = document.getElementById("txtNombres").value;
datos.push(txtNombres);
var txtCurp = document.getElementById("txtCurp").value;
datos.push(txtCurp);
var chkSexo;
if(document.getElementById("chkHombre").checked)
chkSexo = 'H';
else
chkSexo = 'M';
datos.push(chkSexo);
var txtfecha = document.getElementById("txtfecha").value;
datos.push(txtfecha);
var txtEdad = document.getElementById("txtEdad").value;
datos.push(txtEdad);
var txtPeso = document.getElementById("txtPeso").value;
datos.push(txtPeso);
var txtTalla = document.getElementById("txtTalla").value;
datos.push(txtTalla);
var txtCC = document.getElementById("txtCC").value;
datos.push(txtCC);
for (var i=0;i<document.getElementById('table_depProg').rows.length;i++)
{
var prog = [];
for (var j=0;j<1;j++)
{
var programa = document.getElementById('table_depProg').rows[i].cells[j].innerHTML;
alert(programa);
prog.push(programa);
}
window.location.href = "funciones/guardar.php?prog="+prog+"&datos[]="+datos;
}
}
Now the problem is that when I try to take the array with the GET method I can't take the index one by one.
<?php
include("funciones.php");
//Persona
print_r($_GET['datos']);
@$fechacaptura = $_GET['datos']['txtfechaCap'];
@$idlocalidad = $_GET['datos']['cbxLocalidad'];
@$apaterno = $_GET['datos']['txtapellidoP'];
@$amaterno = $_GET['datos']['txtapellidoM'];
@$nombre = $_GET['datos']['txtNombres'];
@$curp = $_GET['datos']['txtCurp'];
@$sexo = $_GET['datos']['chkSexo'];
@$fechanacimiento = $_GET['datos']['txtfecha'];
@$edad = $_GET['datos']['txtEdad'];
@$peso = $_GET['datos']['txtPeso'];
@$talla = $_GET['datos']['txtTalla'];
@$cc = $_GET['datos']['txtCC'];
$sql = "CALL personasAdd($idlocalidad,'$fechacaptura','$apaterno','$amaterno','$nombre','$curp','$sexo', '$fechanacimiento',$edad,$peso,$talla,$cc);";
@$idpersona = personasAdd($sql);
?>
As you can see, I print the array to check how it working but this is the output:
Array ( [0] => 2013-07-03,8,LastName1,LastName2,Name(s),123456789012345678,H,2013-07-01,24,34,45,56 ).
It contains the data but when I print the $sql variable i get this:
CALL personasAdd(,'','','','','','','',,,,);
I've been working in this the whole day and couldn't find what I'm doing wrong, I would really apreciate any help or clue to find my mistake.