PHP errors / warnings parameter 1 & 2 [closed]

2

In my PHP code the following warnings appear:

  

Warning: mysqli_query () expects parameter 2 to be string, object given   in on line 8

     

Warning: mysqli_num_rows () expects parameter 1 to be mysqli_result,   null given in on line 9

I honestly do not understand what this means in practice, what is Parameter 2? I do not quite understand when these warnigns appear to me.

Follow the PHP code:

<?php
include("config.php");
if($_GET['key'] && $_GET['reset'])
{
    $email=password_hash($_GET['key'],PASSWORD_DEFAULT);
    $pass=password_hash($_GET['reset'],PASSWORD_DEFAULT);
    $sql=mysqli_query($conn,"SELECT email, password FROM registo where email='$email' and password='$pass'");
    $r = mysqli_query($conn, $sql); // Linha 8
    $count = mysqli_num_rows($r); // Linha 9
    if(mysqli_num_rows($sql)==1)
    {
?>
<html>
    <form method="post" action="update_newpassword.php">
        <input type="hidden" name="email" value="
<?php echo $email;?>">
        <p>
            Enter New password
        </p>
        <input type="password" name='password'>
        <input type="submit" name="submit_password">
    </form>
</html>
<?php
    }
}
?>
    
asked by anonymous 16.05.2017 / 21:32

2 answers

4

You are passing a query as a parameter instead of SQL on line 8.

Remove line 8, as it is not necessary, and change line 9 (which will become line 8) by changing the variable $r to $sql :

$count = mysqli_num_rows($sql);

Change line 10 (which will become line 9) by setting $count instead of repeating mysqli_num_rows :

 if($count==1)
    
16.05.2017 / 21:48
0

Basically these two lines are doing the same thing

$sql=mysqli_query($conn,"SELECT email, password FROM registo where email='$email' and password='$pass'");
    $r = mysqli_query($conn, $sql); // Linha 8

Use this by passing the command $sql

$count = mysqli_num_rows($r); // Linha 9
    
16.05.2017 / 22:08