Page 1 of 1

error help

Posted: Mon Apr 28, 2008 7:22 am
by jay23

Code: Select all

<?
// Use session variable on this page. This function must put on the top of page.
session_start();
 
////// Logout Section. Delete all session variable.
session_destroy();
 
$message="";
 
////// Login Section.
$Login=$_POST['Login'];
if($Login){ // If clicked on Login button.
$username=$_POST['username'];
$password=$_POST['password']; // Encrypt password with md5() function.
 
// Connect database.
$host="localhost"; // Host name.
$db_user="root"; // MySQL username.
$db_password=""; // MySQL password.
$database="feedbback"; // Database name.
mysql_connect($host,$db_user,$db_password);
mysql_select_db($database);
 
// Check matching of username and password.
$result=mysql_query("select * from admin where username='$username' and password='$password'");
if(mysql_num_rows($result)!='0'){ // If match.
session_register("username"); // Craete session username.
header("location:adlog.php"); // Re-direct to main.php
exit;
}else{ // If not match.
$message="--- Incorrect Username or Password ---";
}
 
} // End Login authorize check.
?>
 
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Admin</title>
</head>
 
<body>
<? echo $message; ?>
<form id="form1" name="form1" method="post" action="<? echo $PHP_SELF; ?>">
<table>
<tr>
<td>User : </td>
<td><input name="username" type="text" id="username" /></td>
</tr>
<tr>
<td>Password : </td>
<td><input name="password" type="password" id="password" /></td>
</tr>
</table>
<input name="Login" type="submit" id="Login" value="Login" />
</form>
</body>
</html>

im geting this error message can some1 help

Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in C:\xampp\htdocs\Login\adminb\index.php on line 26
--- Incorrect Username or Password ---

Re: error help

Posted: Mon Apr 28, 2008 8:02 am
by aceconcepts
Try using mysql_error():

Code: Select all

 
$result=mysql_query("select * from admin where username='$username' and password='$password'") or die(mysql_error());
 
also, when you're checking for an int i.e. 0, 1, 2... you don't need to surround it in quote marks otherwise it becomes a string:

Code: Select all

 
if(mysql_num_rows($result)!='0'){
 
//should be
 
if(mysql_num_rows($result)!=0){