Got an error from mysqli_num_rows when trying to do a query.
Posted: Fri Nov 04, 2005 6:09 am
Could someone please help me find out why I get this error?:
Warning: mysqli_num_rows() expects parameter 1 to be mysqli_result, boolean given in c:\SERVER\htdocs....
here is the code. It just tries to connect to a database:
Please I need your help!
Warning: mysqli_num_rows() expects parameter 1 to be mysqli_result, boolean given in c:\SERVER\htdocs....
here is the code. It just tries to connect to a database:
Code: Select all
<?php
session_start();
if (isset($_POST['userid']) && isset($_POST['password'])) {
// User sent log in through form
// Connection to database:
@$db = mysqli_connect('localhost', 'authenticator', 'passAthenticator', 'authentication'); // authenticator with pass='passAuthenticator' has been granted select privilege on DB 'authentication'. It's not a real user, but just an automatic registrator.
// Connection error?:
if (mysqli_connect_errno()) {
// Error trying to acess database
echo 'There was an error trying to access database. Please try later.<br />';
exit;
}
// Short names for form superglobal vars:
$userid = $_POST['userid'];
$password = $_POST['password'];
// Query:
$myQuery = "select * from authorized_users where name=".$userid." and password=".$password;
$result = mysqli_query($db, $myQuery);
$num_results = mysqli_num_rows($result); // THIS LINE PRODUCES THE ERROR
// Did we get any record containing valid userid and password?
if ($num_results > 0) {
// We got one.
// Creating session var:
$_SESSION['valid_user'] = $userid;
}
// Finish database connection:
mysqli_free_result($result); // THIS LINE PRODUCES ERROR 'CAUSE USES VAR $result TOO
mysqli_close($db);
}
?>