Jump to content

mysql_num_rows() not working


Cagecrawler

Recommended Posts

Here's a piece of code that shows when a user logs into my site:
[code]
        <?php
include("include/connect.php");
$username=$_SESSION['username'];
$sql="SELECT * FROM mail WHERE to='$username' AND read='0'";
$query=mysql_query($sql);
$numrows=mysql_num_rows($query);
$sql2="SELECT * FROM mail WHERE to='$username'";
$query2=mysql_query($sql2);
$numrows2=mysql_num_rows($query2);
echo "<table>";
echo "<tr>";
echo "<td>";
echo "Welcome ".$_SESSION['username']."!<br/>";
echo "Your last visit: ".$_SESSION['lastvisit']."<br/>";
echo "<a href=\"mail.php\" target=\"main\">Mailbox:</a> ".$numrows." unread, total ".$numrows2.".";
echo "</td>";
echo "<td width=\"100\">";
echo "<p align=\"right\"><a href=\"logout.php\">Log out</a></p>";
echo "</td>";
echo "</tr>";
echo "</table>";
        ?>[/code]
I get the following errors:
[code]Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in loginbox.php on line 8

Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in loginbox.php on line 11[/code]

Any ideas why?
Link to comment
https://forums.phpfreaks.com/topic/33676-mysql_num_rows-not-working/
Share on other sites

Hmm...
My connection code:
[code]
<?
//Prepare DB connection
$connection= mysql_connect($server_name,$db_username,$db_password);

//Connect to MySQL and select DB
mysql_select_db($db_name,$connection) or die(mysql_error());
?>
It's already there, so I don't know why the error isn't showing up.  I've also just got it to output $query. Result - No output.

I've used include/connect.php in other files on the site (registering and logging in) and they've worked fine...  [/code]
"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 'to='cagecrawler'' at line 1"

It's showing it's picking up $username ok, but there is a syntax error that I can't see.

$sql2="SELECT * FROM mail WHERE to='$username'";

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.