Warning: mysqli_num_rows()

it say’s: Warning: mysqli_num_rows() expects parameter 1 to be mysqli_result, boolean given in C:\AppServ\www\store\LoginRegister\profile.php on line 31
Warning: mysqli_num_rows() expects parameter 1 to be mysqli_result, boolean given in C:\AppServ\www\store\LoginRegister\profile.php on line 33

[php]<?php
include ‘core/init.php’;
protect_page();
include ‘includes/overall/header.php’;
?>

<?php error_reporting( E_ALL ); ?>
<?php if (isset($_GET['username']) === true and empty($_GET['username']) === false) { $username = $_GET['username']; $username1 = $_SESSION['user_id'];
if(user_exists($username) === true) {
$profile_user_id		= user_id_from_username($username, 'username');
$my_id					= $_SESSION['user_id'];
$profile_data			= user_data($profile_user_id, 'username', 'first_name', 'last_name', 'email', 'profile');
?>
	
	<h1><?php echo $profile_data['first_name']; ?>'s Profile</h1>
	<?php
	if($profile_user_id != $my_id) {
		$check_friend_query = mysql_query("SELECT id FROM friends WHERE (user_one='$my_id' AND user_two='$profile_user_id') OR (user_one='$profile_user_id' AND user_two='$my_id')");
		if(mysql_num_rows($check_friend_query) > 0) {
			echo '<a href="">Already Friends </a>- <a href="">Unfriend '. $profile_data['username'] .'</a>';
		} else {
			$from_query = mysql_query("SELECT id FROM friend_request WHERE from = '$profile_user_id' AND to = '$my_id'");
			$to_query 	= mysql_query("SELECT id FROM friend_request WHERE from = '$my_id' AND to = '$profile_user_id'");
				if(mysqli_num_rows($from_query) == 1){
				 echo '<a href="#">Ignore</a> or <a href="">Accept</a>';
			} elseif(mysqli_num_rows($to_query) == 1){
				 echo '<a href="#">Cancel Request</a>';
			} else {
				 echo '<a href="#">Send Friend Request</a>';
			}
		}
	}
	?>

[/php]

OK ?? < do your queries run without error at the MySQL command prompt?

Yes. Everything in database also ok!What could cause this?

It complains about line 31 and 33

Are these two queries really ok?

SELECT id FROM friend_request WHERE from = '$profile_user_id' AND to = '$my_id' SELECT id FROM friend_request WHERE from = '$my_id' AND to = '$profile_user_id'

Using reserved words (from) as table/column names usually make MySQL act up… If you must use reserved words you must use backticks to let the sql server know they are column names.

backticks are not required at all in query,tho i tried it long ago result was still the same -_-
query’s are all ok rly,every id and in database is good,we’ve checked 100 times,maybe its something disabled in conf?

$check_friend_query - works perfectly, so why shouldn’t others work? =/

Because that query does not have any table/column names with reserved words.

Please try one of the queries I mentioned (with valid IDs), even directly in command line or phpmyadmin you should get an error like this:

#1064 - You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'from > 1' at line 1

I tried:

$from_query = (mysql_query(“SELECT id FROM friend_request WHERE from = ‘$profile_user_id’ AND to = ‘$my_id’”)or die("Error: ".mysql_error()));

$to_query = (mysql_query(“SELECT id FROM friend_request WHERE from = ‘$my_id’ AND to = ‘$profile_user_id’”)or die("Error: ".mysql_error()));

And it said:

Error: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ‘from = ‘30’ AND to = ‘52’’ at line 1

Just like you mentioned,how do i fix this?

like I said, if you have to use reserved words (in this case: from) then you need to use backticks.

So change
from =

to
from =

Weird…It worked now,i quess when i tried it with backticks,something else was wrong,that i changed trying to fix this thing.Thanks alot friend :slight_smile: All the best!

Sponsor our Newsletter | Privacy Policy | Terms of Service