i have this main_login.php code

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<title>Untitled Document</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">

<table width="300" border="0" align="center" cellpadding="0" cellspacing="1" bgcolor="#CCCCCC">
<form name="form1" method="post" action="checklogin.php">
<table width="100%" border="0" cellpadding="3" cellspacing="1" bgcolor="#FFFFFF">
<td colspan="3"><strong>Member Login </strong></td>
<td width="78">Username</td>
<td width="6">:</td>
<td width="294"><input name="myusername" type="text" id="myusername"></td>
<td><input name="mypassword" type="text" id="mypassword"></td>
<td> </td>
<td> </td>
<td><input type="submit" name="Submit" value="Login"></td>

and checklogin.php code

$host="localhost"; // Host name 
$username=""; // Mysql username 
$password=""; // Mysql password 
$db_name="test"; // Database name 
$tbl_name="members"; // 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 

// To protect MySQL injection (more detail about MySQL injection)
$myusername = stripslashes($myusername);
$mypassword = stripslashes($mypassword);
$myusername = mysql_real_escape_string($myusername);
$mypassword = mysql_real_escape_string($mypassword);
$sql="SELECT * FROM $tbl_name WHERE username='$myusername' and password='$mypassword'";

// Mysql_num_row is counting table row

// If result matched $myusername and $mypassword, table row must be 1 row

// Register $myusername, $mypassword and redirect to file "login_success.php"
else {
echo "Wrong Username or Password";

when im trying to log in this warnig appeared "Warning: mysql_num_rows() expects parameter 1 to be resource, boolean given in C:\xampp\htdocs\final\checklogin.php on line 26
Wrong Username or Password"

can anyone help me. i am new to php

Edited by maki.tabasa

4 Years
Discussion Span
Last Post by Will Gresham

mysql_query will return either a resource, or a boolean FALSE depending on the query result.

Boolean FALSE means that there is an error in your query.

It is good practice to try and catch errors in your code, so that messages like this do not appear, for example, on any query I will do something like the following:

$sql = 'Query here';

if(!$res = mysql_query($sql, $connection)) {
    // Query was not successful, handle it here.

Instead of die() on a live page though, you should display a meaningful message to the user, such as 'Error getting (Whatever you are getting)'

Wrapping your mysql_query function in an if means that a failed query can be debugged.

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.