PHP Mysql error - mysql_num_rows()

Asked

Viewed 284 times

0

I’m having trouble correcting this error, I don’t know much about language (almost anything). The error that appears on the page is this:

Warning: mysql_num_rows() expects parameter 1 to be resource, boolean given in C:\Program Files (x86)\EasyPHP-Devserver-17\eds-www\core\inc\user.inc.php on line 10

PHP:

<?php

function validate_credentials($user_name, $user_password){
$user_name = mysql_real_escape_string($user_name);
$user_password = sha1($user_password);

$result = mysql_query("SELECT `user_id` FROM `users` WHERE `user_name` = 
'{$user_name}' AND `user_password` = '{$user_password}'");

if (mysql_num_rows($result) != 1){
    return false;
}

return mysql_result($result, 0);
}

?>

1 answer

0

Follow this example here, because I think you forgot the connection and without it nothing will be returned in your query...

Example #1 Example mysql_num_rows()

<?php

$link = mysql_connect("localhost", "mysql_user", "mysql_password");
mysql_select_db("database", $link);

$result = mysql_query("SELECT * FROM table1", $link);
$num_rows = mysql_num_rows($result);

echo "$num_rows Rows\n";

?>

Link to website where I got the answer.

Browser other questions tagged

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