Check if there are users in the BD

0

I am checking if there are users in my BD through a form to enter the email and password. I check in a PHP file if the mail and the password exist in the database, but I get an error Undefined index: password and I do not know why.

HTML code:

<html>
    <head>
        <title>Introduce tu usuario</title>
        <meta charset="UTF-8">
    </head>
    <body>
        <h1>Introduce tu usuario:</h1>
        <form method="get" action="comprobar.php">
            <label for="correo">Correo:</label>
            <input type="text" name="correo"><br/><br/>
            <label for="password">Contraseña:</label>
            <input type="password" name="password"><br/><br/>
            <input type="submit">
        </form>
    </body>
</html>

Php code:

<?php
    $correo=$_GET["correo"];
    $password=$_GET["password"];

    //Conexion con el servidor de base de datos
    $conexion=mysqli_connect("localhost","root","","bdusuarios");

    //Escribimos la consulta que queremos hacer
    $consulta="SELECT * FROM usuarios";
    //Ejecutamos la consulta
    $resultado = mysqli_query($conexion,$consulta);

    $swcorreo=0;
    $swpassword=0;

    //Vamos leyendo cada fila y comprobando los campos
    while($fila = mysqli_fetch_array($resultado))
    {
        if(strcmp($fila["correo"], $correo) === 0)
        {
            $swcorreo=1;
        }
        if(strcmp($fila["password"], $password) === 0)
        {
            $swpassword=1;
        }
    }

    //Mostramos si existe el usuario
    if($swcorreo==1 && $swpassword==1)
    {
        echo "<h1>La cuenta existe</h1>";
    }else
    {
        echo "<h1>La cuenta no existe</h1>";
    }
?>
    
asked by Mario Guiber 15.10.2017 в 12:52
source

1 answer

1

As the select says "*" instead of listing the fields you need and did not include the line number where the error is presented, I'm guessing:

Notice if the name of the field is really "password" in the database, which affects $ row ["password"] in the program.

    
answered by 15.10.2017 / 13:05
source