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
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]
Link to comment
Share on other sites

"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'";

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.