Why are not you comparing?

0

I have this code to compare the email and the password that are in the database, but always gives the data are wrong, not letting in. What's wrong with the code, can you help me?

<?php

$servername = "localhost";
$username = "isabelso_isabel";
$password = "password";
$dbname = "isabelso_db";


$dbconn = mysqli_connect($servername, $username, $password, $dbname)or die("Failed to connect to database:" . mysqli_error($conn));;


//Get user details and put them on varaiables
        $email = mysqli_real_escape_string($dbconn, $_POST['login']);
        $password = mysqli_real_escape_string($dbconn, $_POST['senha']);

        if (!empty($email) && !empty($password))
        {

        $query = "SELECT * FROM Paciente WHERE email = '$email' AND password = '$password'";
        $data = mysqli_query($dbconn, $query);
        $result = mysqli_num_rows($data);
        printf("Number of rows %d \n", $result);
        if ($result == 1) {

            $row = mysqli_fetch_array($data);
            $email = $row('login');
            $password = $row('senha');
            header("location: marcar_consulta_online.html");
        } else {

            echo  "<script>alert('A password e/ou email est達o erradas');</script>";
        }

        }
        else
        {

            echo  "<script>alert('Deve preencher com o seu email e password);</script>";
            ?>

        <?php
        }
        mysqli_close($dbcon);
        ?>
    
asked by anonymous 16.06.2017 / 16:08

2 answers

3

I think the code is not working because of these lines.

$data = mysqli_query($dbconn, $query);
$result = mysqli_num_rows($dbname);

$ dbname $ data line, so the program never compares, so it should look like this:

$data = mysqli_query($dbconn, $query);
$result = mysqli_num_rows($data);

All the best

    
16.06.2017 / 16:29
0

Oops. $data = mysqli_query($dbconn, $query); $result = mysqli_num_rows($dbname); You have passed dbname in place of $ data, so php does not know where to get the number of lines, so your code is only giving error. The right would be: $data = mysqli_query($dbconn, $query); $result = mysqli_num_rows($data);

    
16.06.2017 / 16:40