PHP errors/warnings parameter 1 & 2

Asked

Viewed 63 times

2

In my PHP code appear the following "warnings":

Warning: mysqli_query() expects Parameter 2 to be string, Object Given in line 8

Warning: mysqli_num_rows() expects Parameter 1 to be mysqli_result, null Given in online 9

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

Follows 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
    }
}
?>
  • Remove this $r and use the $sql in the mysqli_num_rows(). You’re passing the return of mysqli_query to the second mysqli_query and not an SQL statement.

2 answers

4


You’re passing a query as a parameter in place of SQL on line 8.

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

$count = mysqli_num_rows($sql);

Change line 10 (which will be as line 9) by putting the $count instead of repeating the mysqli_num_rows:

 if($count==1)

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

Browser other questions tagged

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