Page 1 of 1

php login error

Posted: Wed Feb 25, 2009 11:52 am
by bex1111
Hi, I'm have created a simple login form and had it working fine. Then suddenly, although nothing was changed it threw up this error:

Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in C:\wamp\www\checklogin.php on line 49

and I just can't seem to solve the problem. Here is my code:

<?php
// Connect to server and select databse.
mysql_connect("localhost","root","bexwilkins");

//specify database
mysql_select_db("main") or die("Unable to select database");

// username and password sent from form
$user=$_POST['user'];
$pass=$_POST['pass'];

// To protect MySQL injection
$user = stripslashes($user);
$pass = stripslashes($pass);
$user = mysql_real_escape_string($user);
$pass = mysql_real_escape_string($pass);

$sql = "SELECT * FROM user WHERE user='$user' AND pass='$pass'";
$result = mysql_query($sql);

// Mysql_num_row is counting table row
$count=mysql_num_rows($result);

// If result matched $myusername and $mypassword, table row must be 1 row
if($count==1)
{
// Register $myusername, $mypassword
//session_start();
session_register("user");
session_register("pass");
header("location: addEvent.php");
}
else
{
echo "Wrong Username or Password";
}
?>
Please help me!!

Thank youuu

Re: php login error

Posted: Thu Feb 26, 2009 3:30 am
by susrisha

Code: Select all

 
if(!$result = mysql_query($sql))
{
echo mysql_error();
}
 
change the line to this and tell us if it shows up an error message

Re: php login error

Posted: Thu Feb 26, 2009 4:29 am
by nmreddy
$count=mysql_num_rows($result);


replace above with

$count = mysql_affected_rows();

Re: php login error

Posted: Thu Feb 26, 2009 4:44 am
by sanju
print the query and check it, its error from query. try that printed query directly in phpmyadmin

Re: php login error

Posted: Thu Feb 26, 2009 4:55 am
by Paul Arnold
Maybe don't post your database password on a public forum too :?

Also, session_start(); has been commented out.