Notice: Undefined index php

2

Hello, I'm trying to send data to a procedure stored in mysql when I send the data to the php I get errors in the image

this is the form in html:

<form method="post" action="llamada.php" name="formulario">

<input type="text" required id="nombre" name="nombre" placeholder="nombre"> </br></br>

<input type="text" required id="apellido" name="apellido" placeholder="apellido"> </br></br>

<input type="text" required id="usuario" name="usuario" placeholder="nombre de usuario"> </br></br>

<input type="password" required id="clave" name="clave" placeholder="contraseña"> </br></br>

<input type="submit" value="Enviar">

</form>

This is the php code that receives the form data and sends it to the stored procedure:

require("coneccion/conexion.php");

print("Coneccion exitosa </br>");

$nombre=$_POST["nombre"];
$apellido= $_POST["apellido"];
$usuario=$_POST["usuario"];
$clave= $_POST["clave"];

print "$nombre, $apellido, $usuario, $clave";

$datos= array($nombre, $apellido, $usuario, $clave);
$procedimiento= $l->prepare("CALL ingresarusuario(?, ?, ?, ?)");
$procedimiento->bind_param("ssss", $datos[$nombre], $datos[$apellido], $datos[$usuario], $datos[$clave]);
$procedimiento->execute();
$procedimiento->close();
$l->close();

    
asked by Agustin Coronel 30.10.2018 в 22:31
source

1 answer

0

The problem is in this line:

$procedimiento->bind_param("ssss", $datos[$nombre], $datos[$apellido], $datos[$usuario], $datos[$clave]);

As the array is defined like this:

$datos= array($nombre, $apellido, $usuario, $clave);

The datos array is actually this:

[ 0 => $nombre, 1 => $apellido, 2 => $usuario, 3 => $clave]

If you want to extract the values as, for example, $datos['nombre'] you have to write those indexes:

$datos= array('nombre' => $nombre, 'apellido' => $apellido, 'usuario' => $usuario, 'clave' => $clave);

Then you can get the data as $datos['nombre'] , $datos['apellido'] , etc. Or you can just use $_POST[indice] .

Note that the index is not $nombre , but a string: 'nombre ', in that case.

    
answered by 31.10.2018 в 19:37