What's wrong with my code? mysql_num_rows() expects parameter 1 to be resource
You try to run 2 queries at once. That does not work with this PHP function. But you can reduce it to one query
SELECT *, @rank:=@rank+1 AS Rank
FROM scoregame
cross join (select @rank := 0) r
where userid=33
order by score DESC
mysql_fetch_array()/mysql_fetch_assoc()/
mysql_fetch_row()/mysql_num_rows etc... expects parameter 1 to be resource
A query may fail for various reasons in which case both the mysql_* and the mysqli extension will return false
from their respective query functions/methods. You need to test for that error condition and handle it accordingly.
mysql_ extension:
NOTE The mysql_ functions are deprecated and have been removed in php version 7.
Check $result
before passing it to mysql_fetch_array
. You'll find that it's false
because the query failed. See the [mysql_query
][1] documentation for possible return values and suggestions for how to deal with them.
$username = mysql_real_escape_string($_POST['username']);
$password = $_POST['password'];
$result = mysql_query("SELECT * FROM Users WHERE UserName LIKE '$username'");
if($result === FALSE) {
trigger_error(mysql_error(), E_USER_ERROR);
}
while($row = mysql_fetch_array($result))
{
echo $row['FirstName'];
}
Related Topics
Send Python Output to HTML Field
Generate an N-Digit Random Number
Install PHP Intl Extension on Macos
How to Convert a 13 Digit Unix Timestamp to Date and Time
Laravel How to Return Single Column Value Using Query Builder
Getting a File to Download Instead of Opening the Browser
Mysql Return Result If 0 Rows Returned
Passing an Array to a Query Using a Where Clause
How to Show Checkboxes as Checked When Values Are Set in the Database in Laravel
How to Run a PHP Script in the Background After a Form Is Submitted
Check If Username and Email Already Exists in Database
How to Remove Duplicate Values from a Multi-Dimensional Array in PHP
Project Links Do Not Work on Wamp Server