Connection failed in Xampp, does not connect to phpmyadmin

0

For some reason, I can not connect to phpmyadmin using this code. In connect_db.php. It says there is a connection problem and it does not give the error number.

<form method="POST" action =""/> <!-- El formulario en si -->
 <label for="nom"><b>Nombre de usuario</b></label>
 <input type="text" placeholder="Escriba su nombre de usuario" name="nombre" id ="nombre"></input>

<label for="clav"><b>Clave</b></label>
<input type="password" placeholder="Escriba su clave de usuario" name="clave" id ="clave"></input>

<label for="em"><b>Email</b></label>
<input type="text" placeholder="Escriba su email" name="email" id ="email"></input>

<label for="ced"><b>Cedula de identidad</b></label>
<input type="text" placeholder="Escriba su cedula de identidad" name="cedula" id ="cedula"></input>

<input type="submit" id="submit" name="submit" class="floated" value="Registrarse"></input>

<div class="container" style="background-color:#f1f1f1">
<button type="Reset" class="floated">Cancelar</button>
</div>

<?php
if(isset($_POST['submit'])){ 
$nombre = $_POST['nombre'];
$clave = $_POST['clave'];
$email = $_POST['email'];
$cedula = $_POST['cedula'];

//esto evita que el usario meta datos en blanco
$reqlen = strlen($nombre) + strlen($clave) + strlen($cedula) + strlen($email);

 if($reqlen > 0){
  require('connect_db.php'); //Algo anda mal aca, no logra conectarse
  $clave = md5($clave);    //Convierte la clave en md5

  mysqli_query("INSERT INTO 'usuarios' VALUES ('', '$nombre', '$clave', '$email', '$cedula')");
  mysqli_close($link);
  echo 'Se ha registrado exitosamente';

}else{
echo 'Por favor rellene los espacios necesarios';  
}
}
?>
</form>

I'm using xampp and mysql if they ask. Due to this error, I can not put data in the database.

The code in connect_db.php:

<?php
// Create connection
$link =  mysqli_connect("localhost", "root", "", "prueba");

// Check connection
if (!$link) {
    die('Connection failed: ' . mysqli_connect_error());
}   

//por alguna razon, la conexion falla todo el tiempo
?>

I appreciate your response.

    
asked by Shredder 21.09.2018 в 17:10
source

1 answer

0

The function is misused:

mysqli_query("INSERT INTO 'usuarios' VALUES ('', '$nombre', '$clave', '$email', '$cedula')");

since you need the connection to the database, the correct thing would be:

mysqli_query($conexionBD,$consultaSQL);

As a recommendation you should discard the use of these functions and start using PDO.

    
answered by 21.09.2018 в 18:03