Jump to content

Warning: mysql_num_rows() expects parameter 1 to be resource


Go to solution Solved by thelostdutchmann,

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>
Link to comment
Share on other sites

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().

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.