php - Warning: mysqli_num_rows() expects parameter 1 to be mysqli_result, string given -


hello stackoverflow community, learning php on own , on figuring out problem given message whenever try login in login page:

warning: mysqli_num_rows() expects parameter 1 mysqli_result, string given in on line 38 $numrows = mysqli_num_rows($query);

<html>     <form action='login.php' method='post'>         <table>             <tr>                 <td>                     username:                     <input type='text' name='username' value='<?php echo $username; ?>'>                 </td>             </tr>             <tr>                 <td>                     password:                     <input type='password' name='password'>                 </td>             </tr>         </table>         <p>         <input type='submit' name='submit' value='login'>     </form> </html> <?php     session_start();     $username = $_post['username'];     $password = $_post['password'];      if ($username&&$password)     {         $dbc = mysqli_connect('webhost', 'admin', 'password', 'database')or die('error connecting mysql server.');          $query = "select username, password users username ='$username' , password = sha('$password')";         $numrows = mysqli_num_rows($query);  //the line error lies in         $result = mysqli_query($dbc, $query) or die(mysqli_error($dbc));         $numrows = mysqli_num_rows($result);          if ($numrows!=0)         {              while ($row = mysqli_fetch_assoc($query))             {                 $dbusername = $row['username'];                 $dbpassword = $row['password'];             }              if ($username==$dbusername&&md5($password)==$dbpassword)             {                 echo "you're in! <a href='report.php'>click here enter!</a>";                 $_session['username']=$dbusername;                 mysqli_close($dbc);             }             else                 echo "incorrect password!";          }         else             die("that user doesn't exist!");      }     else         die("please enter username , password.");     ?> 

my online host displays error message php book doesn't seem cover should in topic. seems expecting string yes, can't figure out how make work.

first must execute query num record

this incorrect

$numrows = mysqli_num_rows($query);  //the line error lies in $result = mysqli_query($dbc, $query) 

and correct is

if ($result=mysqli_query($dbc,$query )) {   // return number of rows in result set   $numrows =mysqli_num_rows($result);       } 

Comments

Popular posts from this blog

python - Installing PyDev in eclipse is failed -

PHP OOP-based login system -

c# - Nested Internal Class with Readonly Hashtable throws Null ref exception.. on assignment -