When i run this code, i keep getting this message;
Warning: mysql_num_rows( ): supplied argument is not a valid MySQL result resource in C:\wamp\www\che cklogin.php on line 26
i use this code to check login details. Here is the code for the pages that i used.
main_login.php
[PHP]<html>
<body>
<table width="300" border="0" align="center" cellpadding="0" cellspacing="1" bgcolor="#CCCCC C">
<tr>
<form name="form1" method="post" action="checklo gin.php">
<td>
<table width="100%" border="0" cellpadding="3" cellspacing="1" bgcolor="#FFFFF F">
<tr>
<td colspan="3"><st rong>Member Login </strong></td>
</tr>
<tr>
<td width="78">User name</td>
<td width="6">:</td>
<td width="294"><in put name="myusernam e" type="text" id="myusername" ></td>
</tr>
<tr>
<td>Password</td>
<td>:</td>
<td><input name="mypasswor d" type="text" id="mypassword" ></td>
</tr>
<tr>
<td> </td>
<td> </td>
<td><input type="submit" name="Submit" value="Login"></td>
</tr>
</table>
</td>
</form>
</tr>
</table>
</body>
</html>[/PHP]
checklogin.php
[PHP]<?php
$host=""; // Host name
$username=""; // Mysql username
$password=""; // Mysql password
$db_name=""; // Database name
$tbl_name=""; // Table name
// Connect to server and select databse.
mysql_connect(" $host", "$username" , "$password" )or die("cannot connect");
mysql_select_db ("$db_name") or die("cannot select DB");
// username and password sent from form
$myusername=$_P OST['myusername'];
$mypassword=$_P OST['mypassword'];
// To protect MySQL injection (more detail about MySQL injection)
$myusername = stripslashes($m yusername);
$mypassword = stripslashes($m ypassword);
$myusername = mysql_real_esca pe_string($myus ername);
$mypassword = mysql_real_esca pe_string($mypa ssword);
$sql="SELECT * FROM $tbl_name WHERE username='$myus ername' and password='$mypa ssword'";
$result=mysql_q uery($sql);
// Mysql_num_row is counting table row
$count=mysql_nu m_rows($result) ;
// If result matched $myusername and $mypassword, table row must be 1 row
if($count==1){
// Register $myusername, $mypassword and redirect to file "login_success. php"
session_registe r("myusername") ;
session_registe r("mypassword") ;
header("locatio n:login_success .php");
}
else {
echo "Wrong Username or Password";
}
?>[/PHP]
login_success.p hp
[PHP]<?
session_start() ;
if(!session_is_ registered(myus ername)){
header("locatio n:main_login.ph p");
}
?>
<html>
<body>
Login Successful
</body>
</html>[/PHP]
could anyone see the error on the check login page.
Warning: mysql_num_rows( ): supplied argument is not a valid MySQL result resource in C:\wamp\www\che cklogin.php on line 26
i use this code to check login details. Here is the code for the pages that i used.
main_login.php
[PHP]<html>
<body>
<table width="300" border="0" align="center" cellpadding="0" cellspacing="1" bgcolor="#CCCCC C">
<tr>
<form name="form1" method="post" action="checklo gin.php">
<td>
<table width="100%" border="0" cellpadding="3" cellspacing="1" bgcolor="#FFFFF F">
<tr>
<td colspan="3"><st rong>Member Login </strong></td>
</tr>
<tr>
<td width="78">User name</td>
<td width="6">:</td>
<td width="294"><in put name="myusernam e" type="text" id="myusername" ></td>
</tr>
<tr>
<td>Password</td>
<td>:</td>
<td><input name="mypasswor d" type="text" id="mypassword" ></td>
</tr>
<tr>
<td> </td>
<td> </td>
<td><input type="submit" name="Submit" value="Login"></td>
</tr>
</table>
</td>
</form>
</tr>
</table>
</body>
</html>[/PHP]
checklogin.php
[PHP]<?php
$host=""; // Host name
$username=""; // Mysql username
$password=""; // Mysql password
$db_name=""; // Database name
$tbl_name=""; // Table name
// Connect to server and select databse.
mysql_connect(" $host", "$username" , "$password" )or die("cannot connect");
mysql_select_db ("$db_name") or die("cannot select DB");
// username and password sent from form
$myusername=$_P OST['myusername'];
$mypassword=$_P OST['mypassword'];
// To protect MySQL injection (more detail about MySQL injection)
$myusername = stripslashes($m yusername);
$mypassword = stripslashes($m ypassword);
$myusername = mysql_real_esca pe_string($myus ername);
$mypassword = mysql_real_esca pe_string($mypa ssword);
$sql="SELECT * FROM $tbl_name WHERE username='$myus ername' and password='$mypa ssword'";
$result=mysql_q uery($sql);
// Mysql_num_row is counting table row
$count=mysql_nu m_rows($result) ;
// If result matched $myusername and $mypassword, table row must be 1 row
if($count==1){
// Register $myusername, $mypassword and redirect to file "login_success. php"
session_registe r("myusername") ;
session_registe r("mypassword") ;
header("locatio n:login_success .php");
}
else {
echo "Wrong Username or Password";
}
?>[/PHP]
login_success.p hp
[PHP]<?
session_start() ;
if(!session_is_ registered(myus ername)){
header("locatio n:main_login.ph p");
}
?>
<html>
<body>
Login Successful
</body>
</html>[/PHP]
could anyone see the error on the check login page.
Comment