php login error

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
bex1111
Forum Newbie
Posts: 1
Joined: Wed Feb 25, 2009 11:48 am

php login error

Post 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
User avatar
susrisha
Forum Contributor
Posts: 439
Joined: Thu Aug 07, 2008 11:43 pm
Location: Hyderabad India

Re: php login error

Post 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
nmreddy
Forum Commoner
Posts: 25
Joined: Wed Feb 18, 2009 5:36 am

Re: php login error

Post by nmreddy »

$count=mysql_num_rows($result);


replace above with

$count = mysql_affected_rows();
User avatar
sanju
Forum Commoner
Posts: 65
Joined: Sat Jun 21, 2008 2:15 am
Location: Kochi, India

Re: php login error

Post by sanju »

print the query and check it, its error from query. try that printed query directly in phpmyadmin
Paul Arnold
Forum Contributor
Posts: 141
Joined: Fri Jun 13, 2008 10:09 am
Location: Newcastle Upon Tyne

Re: php login error

Post by Paul Arnold »

Maybe don't post your database password on a public forum too :?

Also, session_start(); has been commented out.
Post Reply