Hi all,
I'm working on a login system for my site. But when I use mysql_num_rows I get an error

"Warning: mysql_num_rows() expects parameter 1 to be resource, boolean given in /home/patrickm129/patthepcwizard.com/login02.php on line 25"

. I'd really appreciate it if you would be able to solve this with me.

P.S.: The error is in login02.php.
<p></p>
login.php

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Untitled Document</title>
<style type="text/css">
<!--
body,td,th {
	color: #FFFFFF;
}
body {
	background-color: #000000;
}
-->
</style></head>

<body>

<form action='login02.php' method="post">
	<p>Username:
	  <input type="text" name="username">
	  <br>Password:
	  <input type="password" name="password">
	  <br>
	  <input type="submit" value="Login">
</p>
</body>
</html>

login02.php

<style type="text/css">
<!--
body,td,th {
	color: #FFFFFF;
}
body {
	background-color: #000000;
}
-->
</style>
<?php

$username = $_POST['username'];
$password = $_POST['password'];

if ($username&&$password)
{
	//Connect to DB
	$mysql_connection = mysql_connect("My DNS", "USERNAME", "PASSWORD");
	if (!$mysql_connection) die("mysql_connect() failed");
	if (!mysql_select_db("DB NAME", $mysql_connection)) die("mysql_select_db() failed");
	//Accesses users
	$query = mysql_query("SELECT * FROM users WHERE login='$username'");
	//Checks if users do not exist (Checks rows)
	$num_result = mysql_num_rows($query);
	echo $num_result;
}
else
	die("Opps! It looks like you left a field empty!");
?>
//Accesses users
$query = mysql_query("SELECT * FROM users WHERE login='$username'");
//Checks if users do not exist (Checks rows)
if($query)
{
	$num_result = mysql_num_rows($query);
	echo $num_result;
}
else
{
	echo 'No result in select query';
	exit;
}

Try this and post output.

I think you miss to close the form </form>
try to

//in login02.php
//after <?
//add
print_r($_POST); to see if field empty or not
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.