Show blank page

0

I know that the code has some errors since I'm starting, please be patient, I made the corrections and I organized it a little better.

$conexion = new PDO('mysql:host=host;dbname=db','root', '');
$login=$conexion->prepare("SELECT nombre_usuario,contrasena from usuario where nombre_usuario=':usuario'");

$login->bindParam(':usuario',$usuario,PDO::PARAM_STR);
$login->execute();

foreach ($login as $row) {

            if($contrasena==password_verify($contrasena,$row['contrasena'])){
                echo "Usuario Correcto";
            }
            else if($row['nombre_usuario']=='' || $contrasena!=password_verify($contrasena,$row['contrasena'])) {

                echo "Usuario o contraseña incorrectos, por favor verificar";

            }
        }

On the blank page after executing echo error_reporting (E_ALL) ;, this number comes out 22527.

    
asked by SbsMtz 25.06.2018 в 03:45
source

2 answers

0

At first glance, it would seem that there is an error with the quotes here:

$login=$conexion->prepare("SELECT nombre_usuario,contrasena from usuario 
where nombre_usuario=':usuario'");

When you use bindParam () it is not necessary to encapsulate the value in the query in quotes, so it would look like this:

$login=$conexion->prepare("SELECT nombre_usuario,contrasena from usuario 
where nombre_usuario=:usuario");

On the other hand, instead of bindParam() you would use bindValue() :

$login->bindValue(":usuario", $usuario, PDO::PARAM_STR);

I hope it helps you!

    
answered by 27.06.2018 в 16:05
0

IN the connection I'm missing localhost ..

$ connection = new PDO ('mysql: host = host; dbname = db', 'root', ''); So it would be:

$ connection = new PDO ('mysql: host = localhost ; dbname = db', 'root', '');

    
answered by 28.06.2018 в 18:55