How to fix php error Warning: mysql_num_rows() expects parameter 1 to be resource, boolean given ?

Sultan

New member
I'm following a tutorial on php private messaging system.
On pm.inbox.php , I'm facing these errors.

Warning: mysql_num_rows() expects parameter 1 to be resource,
boolean given in C:\wamp\www\post\includes\pm_inbox.php on line 48

Warning: mysql_fetch_array() expects parameter 1 to be resource,
string given in C:\wamp\www\post\includes\pm_inbox.php on line 59

pm_inbox.php code is here.

<?php

session_start();

require_once 'connect_i.php';
/*$email = $_POST['email'];*/
$myConnection = mysqli_connect("$db_host",
"$db_username","$db_pass","$db_name")
or die("Could Not Connect to MySQL");
$sqlCommand = " SELECT id, email FROM users
WHERE email='" . $_SESSION['email'] . "' ";
$query = mysqli_query($myConnection,
$sqlCommand) or die (mysqli_error());
while ($row = mysqli_fetch_array($query)){
$pid = $row["id"];
$email = $row["email"];
}
mysqli_free_result($query);

$sqlCommand =
" SELECT COUNT(id) AS numbers FROM pm_inbox
WHERE userid = '$pid' ";
$query = mysqli_query($myConnection, $sqlCommand) or die (mysql_error());
$result = mysqli_fetch_assoc($query);

$inboxMessages = $result['numbers'];

?>

<html>
<head></head>
<body>
<table width="800" border="0">
<tr>
<td>PHP Private message tutorial</td>
</tr>
</table><br>
<?php if ($_SESSION['email']) { ?>
<table width="800" border="0">
<tr>
<td>Welcome back <?php print $email; ?></td>
</tr>
<tr>
<td>Welcome back <?php require_once "pm_check.php"; ?>
</td>
</tr>
</table>
<br>
<?php
require_once "connect.php";

$sql = " SELECT * FROM pm_inbox WHERE userid =
'$pid' ORDERED by DESC ";
$result = mysql_query($sql);

$count = mysql_num_rows($result);

?>
<table width="800" border="0">
<form name="form1" method="post" action="pm_inbox.php">
<tr>
<td width="41" align="center">#</td>
<td width="490">Title:</td>
<td width="255">From:</td>
</tr>
<?php
while($rows = mysql_fetch_array('$result')){
?>
<?php if ($rows['viewed'] == 0){ // show messages in bold ?>
<tr>
<td width="41" align="center">
<input type="checkbox" id="checkbox[]" value="
<?php echo $rows['id']; ?>"></td>
<td width="490"><a href="pm_view_in.php?in=
<?php echo $rows['id']; ?>"><b><?php echo $rows['title']; ?>
</b></a></td>
<td width="255"><?php echo $rows['from_email']; ?></td>
</tr>
<?php } else if ($rows['viewed'] == 1) { ?>
<tr>
<td width="41" align="center">
<input type="checkbox" id="checkbox[]"
value="<?php echo $rows['id']; ?>"></td>
<td width="490"><a href="pm_view_in.php?in=
<?php echo $rows['id']; ?>"><?php echo $rows['title']; ?></a></td>
<td width="255"><?php echo $rows['from_email']; ?></td>
</tr>
<?php } ?>
<?php } ?>
<tr>
<td colspan="3" align="center">
<?php if ($inboxMessages > 0) { ?>
<input type="submit" name="delete" id="delete"
value="Delete Selected Messages"><?php }
else { print "There are no messages in your inbox"; }
?> </td>
</table>

<?php } else { ?>
<table width="800" border="0">
<tr>
<td>Please Login <a href="http://www\index.php"></a></td>
</tr>
</table>
<?php } ?>

</body>
</html>

Can Some one tell me what is the actual reason ?
I try to find in google but it tells that mysql query is failed.
If it is, then how to make a query working?
 
Back
Top