Notice: Undefined variable Warning: mysqli_query () expects parameter 1 to be mysqli, string given

0

I have this code in registry.php but when I get the values from the index.php form when the entries are not added to the database.

<?php
//conexion con la base de datos y el servidor
 $connection = mysqli_connect('localhost', 'root', "", 'formulario');
  if (!$connection) {
  die("Database connection failed: " . mysqli_connect_error());
}
// 2. Select a database to use 
$db_select = mysqli_select_db($connection, 'formulario');
 if (!$db_select) {
 die("Database selection failed: " . mysqli_error($connection));
}
//obtenemos los valores del formulario
$nombres = $_POST['nombreuser'];
$apellidos = $_POST['apellidosuser'];
$email = $_POST['emailuser'];
$pass = $_POST['pass'];
$rpass = $_POST['rpass'];

//Obtiene la longitus de un string
$req = (strlen($nombres)*strlen($apellidos)*strlen($email)*strlen($pass)*strlen($rpass)) or die("No se han llenado todos los campos");

//se confirma la contraseña
if ($pass != $rpass) {
    die('Las contraseñas no coinciden, Verifique <br /> <a href="index.html">Volver</a>');
}

//se encripta la contraseña
$contraseñaUser = md5($pass);

//ingresamos la informacion a la base de datos
mysqli_query($connection,"INSERT INTO datos (nombres,apellidos,email,password)VALUES('','$nombres','$apellidos','$email','$contraseñaUser')" or die("<h2>Error Guardando los datos</h2>"));

echo'
    <script>
        location.href="index.html";
    </script>
'

? >

    
asked by Braulio Rojas 26.07.2018 в 05:06
source

1 answer

0

This was the error that I could notice, you should first put in a variable the mysqli_query sentence and second I do not understand why the empty quotes since you are referring to a field that does not exist

mysqli_query($connection,"INSERT INTO datos (nombres,apellidos,email,password)VALUES('','$nombres','$apellidos','$email','$contraseñaUser')" or die("<h2>Error Guardando los datos</h2>"));

the right thing would be

$sql=mysqli_query($connection,"INSERT INTO datos (nombres,apellidos,email,password)VALUES('$nombres','$apellidos','$email','$contraseñaUser')" or die("<h2>Error Guardando los datos</h2>"));
    
answered by 26.07.2018 в 15:17