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");
?>

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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.. :|

 

Link to comment
Share on other sites

"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.

 

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.