am geting this error while testing the login panel of my website that am currently developing.
Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in /home/smartie1/public_html/checklog.php on line 43 which is in red
this is the php script used for login
<?php
session_start();
function session_defaults() {
$_SESSION['logged'] = false;
$_SESSION['uid'] = 0;
$_SESSION['username'] = '';
$_SESSION['cookie'] = 0;
$_SESSION['remember'] = false;
}
if (!isset($_SESSION['uid']) ) {
session_defaults();
}
$host="localhost"; // Host name
$username="root"; // Mysql username
$password=""; // Mysql password
$db_name="XXXXXX[CODE][/CODE]"; // Database name
$tbl_name="Customer_Infor"; // Table name
// Connect to server and select databse.
$con = mysql_connect("localhost","XXXXXX","YYYYY");
if (!$con)
{
die ('could not connect: '.mysql_error());
}
mysql_select_db("XXXXXX", $con)
or die("cannot select DB");
// username and password sent from form
$username=$_POST['username'];
$password=$_POST['password'];
// To protect MySQL injection (more detail about MySQL injection)
$username = stripslashes($username);
$password = stripslashes($password);
$username = mysql_real_escape_string($username);
$password = mysql_real_escape_string($password);
$sql="SELECT username,password FROM Customer_Infor WHERE username='$username' and
password='$password'";
$result=mysql_query($sql);
// Mysql_num_row is counting table row
[COLOR="Red"]$count=mysql_num_rows($result);[/COLOR]
// If result matched $email and $password, table row must be 1 row
if($count==1){
// Register $myusername, $mypassword and redirect to file "login_success.php"
session_register("username");
session_register("password");
//header("location:loginRedirect.php");
echo"welcome";
}
else {
echo "Wrong Username or Password";
//header("location:Wronglogin.html");
}
?>