Jump to content

num_rows issue, Warning: mysql_num_rows() expects parameter 1 to be resource, boolean given


Go to solution Solved by .josh,

Recommended Posts

Well basically my html form is at the bottom of the code. Then I just use the $_Post function to get what was input. And then a bunch of if statements to check if you are entering a legit email, duplicate usernames etc etc. Line 50 is the final if statement and it should register the user. But it keeps spitting this error at me:  Warning: mysql_num_rows() expects parameter 1 to be resource, boolean given in C:\wamp\www\Swapezee\register.php on line 33. It reads this error for line 33, 36, and 48 so basically anywhere num_rows is used. There is no new user in the DB so the error is effecting the functionality of the program. Any idea how to fix this?




<?php
	error_reporting(E_ALL^ E_NOTICE);
?>


<html>

<head>
	
</head>

<body>
	<?php
	if ($_POST['registerbtn']) {
		$getuser = $_POST['user'];
		$getemail = $_POST['email'];
		$getpass = $_POST['pass'];
		$getretypepass = $_POST['retypepass'];
		
		if ($getuser) {
			
			if ($getemail) {
				if ($getpass) {
					if ($getretypepass) {
						if ($getpass === $getretypepass) {
							if ( (strlen($getemail) >= 7) && (strstr($getemail,"@")) && (strstr($getemail, ".")) ) {
								require("connect.php");
								
								$query = mysql_query("SELECT * FROM users WHERE username='$getuser'");
								$numrows = mysql_num_rows($query);
								if ($numrows == 0) {
									$query = mysql_query("SELECT * FROM users WHERE email='$getemail'");
									$numrows = mysql_num_rows($query);
									if ($numrows == 0) {
						
										$password = md5(md5("R4E2M0".$password."R4E2M0"));
										$date = date("F d, Y");
										$code = md5(rand());
										
										mysql_query("INSERT INTO users VALUES (
											'','$getuser','$password','$getemail','1','$code','$date'
										)");
										
										$query = mysql_query("SELECT * FROM users WHERE username ='$getuser'");
										$numrows = mysql_num_rows($query);
										if ($numrows == 1) {
										echo "Thanks your account has been created!";	
										
										} else {
											$errormsg = "An error has occured. Your account was not created.";
										}
										
								
									} else {
									$errormsg = "There is already a user with that email.";
									}		
									
								} else {
									$errormsg = "There is already a user with that username.";
								}		
								
								mysql_close();
							} else {
								$errormsg = "You must enter a valid email address to register.";
							}
						} else {
							$errormsg = "Your passwords did not match.";
						}
					} else {
						$errormsg = "You must retype your password to register.";
					}
				} else {
					$errormsg = "You must enter your password to register.";
				}
			} else{
				$errormsg = "You must enter your email to register.";
			}
			
		} else {
			$errormsg = "You must enter your username to register.";
		}
		
}
	
	echo "$form";
	
	
	$form = "<form action='register.php' method='post'>
	<table>
	<tr>
		<td></td>
		<td><font color='red'>$errormsg</font></td>
	</tr>
	<tr>
		<td>Username:</td>
		<td><input type='text' name='user' value'$getuser'/></td>
	</tr>
	<tr>
		<td>Email:</td>
		<td><input type='text' name='email' value'$getemail'/></td>
	</tr>
	<tr>
		<td>Password:</td>
		<td><input type='password' name='pass' value=''/></td>
	</tr>
	<tr>
		<td>Re-type Password:</td>
		<td><input type='password' name='retypepass' value=''/></td>
	</tr>
	<tr>
		<td></td>
		<td><input type='submit' name='registerbtn' value='Register!'/></td>
	</tr>
	
	</form>";

	echo "$form";

	?>
</body>	
	
	
	
	
</html>
  • Solution

It means your query is failing.  Change your mysql_query line(s) to this:

 

 

$query = mysql_query("SELECT * FROM users WHERE username='$getuser'") or die(mysql_error());

 

what does it output?

It means your query is failing.  Change your mysql_query line(s) to this:

$query = mysql_query("SELECT * FROM users WHERE username='$getuser'") or die(mysql_error());

what does it output?

It turns out my table name was just user instead of users. That is where programming can be frustrating haha. Thanks for the help mate.

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.