Hello colleagues, I have a big problem with inserting into the DB and I can't find the error, I need help to solve it and learn from it, it shows me that the error is in the or die but I can't find anything in it.
<?php
include 'conexion.php';
if (isset($_POST['submit'])) {
$nombre = $_POST['nombre'];
$apellido = $_POST['apellido'];
$correo = $_POST['correo'];
$telefono = $_POST['telefono'];
$codigo = mt_rand (1,9999999999);
$usuario = $_POST['usuario'];
$password = $_POST['password'];
$password2 = $_POST['password2'];
$añadir = mysqli_query($conexion,"INSERT INTO colaborador(`id-colaborador`, `nombre`, `apellido`, `correo`, `telefono`, `codigo`, `usuario`, `contraseña`)
VALUES (NULL, '$nombre', '$apellido', '$correo', '$telefono', '$codigo', '$usuario', '$password')")
or die ($conexion."Problemas en el insert de colaboradores");
echo ' <script language="javascript"> alert("Colaborador registrado con éxito");</script> ';
}
?>
Try modifying your query
INSERT
like this:or die
methodmysqli_query()
leaving only the variable$conexion
and the sql queryCode
Later to verify if the connection was carried out we do this:
!
that if it was not carried out, print a message and otherwise print anotherCode
Finally consider:
id
isPK
yAUTO_INCREMENT
you don't need to call the column and also don't assign a valueNULL
ñ