Jump to content

Warning: mysql_num_rows() expects parameter 1 to be resource


Recommended Posts

hey i was typing a smale login code but i keep geting this waring

 

Warning: mysql_num_rows() expects parameter 1 to be resource, boolean given in /home/u400486/domains/u400486.gluweb.nl/public_html/lekkerpittig/register.php on line 17

 

and it won't save on my table but i tink thats becouse of the waring

 

can someone help out

<?php

include('config.php');
if($_SERVER['REQUEST_METHOD'] == 'POST'){
	$username = mysql_real_escape_string($_POST['username']);
	$password = mysql_real_escape_string(md5($_POST['password']));
		
if(empty($username)){
	echo("you have to fill in an username!");
	}
	else{
		if(empty($password)){
			echo("you have to fill in a password!");
			}
		else{
			$query = mysql_query("SELECT * FROM users WHERE username ='$username'");
			
			$rows = mysql_num_rows($query);
			
			if($rows > 0){
				die ("Username taken!");
			}else{
				$user_input = mysql_query("INSERT INTO users(username , password) VALUES('$username' , '$password')"); 
				echo("succesfully registered!");
				
}
}
	
}
}

		


?>
<html>
<head>
<title>register</title>
</head>
<body>
<form action="register.php" method="post"/>
username: <input type="text" name="username"/>

<br />
password: <input type="password" name="password"/>

<br />
<input type="submit" value="resister!" />
</form>

</body>
</html>

Your query is failing for whatever reason and you are doing absolutely no error handling to accommodate it.

 

Check that $query (also a nonsensical name for this variable) is what mysql_num_rows is expecting before blindly passing it in.

 

You can find out why your query os failing by looking at the output from mysql_error().

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.