Jump to content

Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resourc


shortysbest

Recommended Posts

I am making a user login and registration page and i have it setup and it works 100% perfect on my localhost, but now i am trying to set it up on my webserver but i get that error message. it says this line of code is not a valid MySQL result resource

 

$numrows = mysql_num_rows($query);

 

This is my whole login.php code

 

<?php
session_start();

$username = $_POST['username'];
$password = $_POST['password'];

if ($username&&$password)
{
$connect = mysql_connect("localhost","*******","******") or die ("couldn't connect!");
mysql_select_db("k297merchanting_zzl_members") or die("couldn't find db");

$query = mysql_query("SELECT * FROM users WHERE username='$username'");

$numrows = mysql_num_rows($query);

if ($numrows!=0)
{
while ($row = mysql_fetch_assoc($query))

	{
		$dbusername = $row['username'];
		$dbpassword = $row['password'];
	}
//check to see if they match
if ($username==$dbusername&&md5($password)==$dbpassword)
{

header ("location:../sw.php?page=item");
echo "Login Successful. You are being redirected to the members page.";
$_SESSION['username']=$dbusername;
}
else 
echo "Incorrect Password!";

}
else
die("That user doesn't exist!");


}
else
die("please enter a username and a password");
?>

Try changing the query line to this:

$query = mysql_query("SELECT * FROM users WHERE username='$username'") or die(mysql_error());

 

You are not checking if the query works or not, Therefor mysql_num_rows fails as there's obviously a problem.

Try changing the query line to this:

$query = mysql_query("SELECT * FROM users WHERE username='$username'") or die(mysql_error());

 

You are not checking if the query works or not, Therefor mysql_num_rows fails as there's obviously a problem.

Thanks, that got rid of the errors. but im still having troubles connecting to my database on my server.. :|

 

"localhost"

 

Most of the shared host *SQL server hosts I've worke with were not "localhost", Why not look in the FAQ's or ask your hosting support?

 

mine is. it says it in the details box.

 

MySQL Hostname

 

    * localhost

 

 

but do you know any good php hosting sites w/ easy to use mysql hosting and all. preferably free to use. i havent had much look finding any good php hosts.

 

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.