php login error
Posted: Wed Feb 25, 2009 11:52 am
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
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