Estoy tratando de insertar datos en la bd pero dos variables me salen como undefined, no logro saber el porque
Notice: Undefined index: id in C:\xampp\htdocs\MIDAS\insertCliente.php on line 14
Notice: Undefined index: sucursal in C:\xampp\htdocs\MIDAS\insertCliente.php on line 15
Los datos los traego de un store procedure y el row lo asigne a una variable
echo"<br>";
while($rows=sqlsrv_fetch_array($stmt)){
echo "Id: ".$rows[11]."<br>";
echo "Sucursal: ".$rows[12]."<br>";
$id = $rows[11];
$sucursal = $rows[12];
}
y los trae correctamente
Como se puede observar
Despues los envio por post en un action hacie insertCliente.php
<form class="form-horizontal" action="insertCliente.php" method="POST" >
En la insercion de datos la tengo así
<?php
require('conexion.php');
$cliente = filter_var(strtolower($_POST['cliente']), FILTER_SANITIZE_STRING);
$calle = filter_var(strtolower($_POST['calle']), FILTER_SANITIZE_STRING);
$numero = filter_var(strtolower($_POST['numero']), FILTER_SANITIZE_NUMBER_INT);
$Ttel = filter_var(strtolower($_POST['Ttel']), FILTER_SANITIZE_STRING);
$ciudad = filter_var(strtolower($_POST['ciudad']), FILTER_SANITIZE_STRING);
$rfc = filter_var(strtolower($_POST['rfc']), FILTER_SANITIZE_STRING);
$estado = filter_var(strtolower($_POST['estado']), FILTER_SANITIZE_STRING);
$cp = filter_var(strtolower($_POST['cp']), FILTER_SANITIZE_NUMBER_INT);
$email = filter_var(strtolower($_POST['email']), FILTER_SANITIZE_EMAIL);
$Tcliente = filter_var(strtolower($_POST['Tcliente']), FILTER_SANITIZE_STRING);
$id = filter_var(strtolower($_POST['id']), FILTER_SANITIZE_NUMBER_INT);
$sucursal = filter_var(strtolower($_POST['sucursal']), FILTER_SANITIZE_STRING);
$insertar="INSERT into CatClientes(C_Nombre, C_Direccion)VALUES('$cliente','$calle')";
$insertardos="INSERT into CatCiudades(Cd_Descripcion)VALUES ('$ciudad')";
$insertartres="INSERT into CatClientesEmails(Mail_Descripcion)VALUES('$email')";
$insertarcuatro="INSERT into CatClientes(C_Numero, C_RFC, C_Cp)VALUES('$numero', '$rfc', '$cp')";
$insertarcuatro= " INSERT into CatClientes(C_Id, C_Centro)VALUES('id','$sucursal')";
$stmt = sqlsrv_query($conn, $insertar);
$stmtdos = sqlsrv_query($conn, $insertardos);
$stmttres = sqlsrv_query($conn, $insertartres);
$stmtcuatro = sqlsrv_query($conn, $insertarcuatro);
//<?php echo "<img src=\"https://api.qrserver.com/v1/create-qr-code/?size=250x250&data=".$cliente." />";
var_dump($insertar);
var_dump($insertardos);
var_dump($insertartres);
var_dump($insertarcuatro);
//header("location:index.php");
?>
Me da este error en sql
Msg 515, Level 16, State 2, Line 4 Cannot insert the value NULL into column 'C_Id', table 'MIDAS.dbo.CatClientes'; column does not allow nulls. INSERT fails. The statement has been terminated. Msg 515, Level 16, State 2, Line 5 Cannot insert the value NULL into column 'Cd_Id', table 'MIDAS.dbo.CatCiudades'; column does not allow nulls. INSERT fails. The statement has been terminated. Msg 515, Level 16, State 2, Line 6 Cannot insert the value NULL into column 'C_Centro', table 'MIDAS.dbo.CatClientesEmails'; column does not allow nulls. INSERT fails. The statement has been terminated. Msg 245, Level 16, State 1, Line 7 Conversion failed when converting the varchar value 'mds corporacion' to data type int.
name="id"
yname = "sucursa"l
– Arreguin92 el 12 jun. a las 16:54$insertarcuatro= " INSERT into CatClientes(C_Id, C_Centro)VALUES('id','$sucursal')";
la variable id es null quiero pensar que es porque le falta el caracter$
, tu consulta debería ser algo así:$insertarcuatro= " INSERT into CatClientes(C_Id, C_Centro)VALUES('$id','$sucursal')";
– Arreguin92 el 12 jun. a las 17:07