Why aren’t you comparing?

Asked

Viewed 38 times

0

I have this code to compare the email and password that are in the database, but it is always possible that the data is wrong, not letting in. What’s wrong with the code, can 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);
        ?>
  • $result = mysqli_num_rows($date);

  • this type of error does not deserve an answer, just a comment

2 answers

3


I think the code is not working due to these lines.

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

'Cause you’re looking for the line $dbname not of $date,so the program never gets to compare, so it should be like this:

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

All the best

  • Already compared... But for example, when you assume that the data is the same you should open another file... Wouldn’t this line do that? header("Location: marcar_consulta_online.html");

  • Yes, it would, but probably the program is failing on the line $email = $Row('login'); $password = $Row('password'); should be used [] instead of ()

0

Opa. $data = mysqli_query($dbconn, $query); $result = mysqli_num_rows($dbname); You passed dbname instead of $data ai php does not know where to pick up the amount of lines, so your code is just giving error. the right would be: $data = mysqli_query($dbconn, $query); $result = mysqli_num_rows($data);

Browser other questions tagged

You are not signed in. Login or sign up in order to post.