Jump to content


PHP - mysql_num_rows() Error


1 reply to this topic

#1 Mitchell

    Young Padawan

  • Members
  • Pip
  • 1 posts

Posted 22 May 2007 - 04:27 PM

Hey, I've been looking at a registration script, found on here, partly by myself... I'm only a beginner with MySQL you see.

Anyway the error I'm coming up with is...

Quote

Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in /home/mitchpe/public_html/page/create_member.txt on line 24

Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in /home/mitchpe/public_html/page/create_member.txt on line 27


Here is my code...

<?php
 //Connect to the database using con_members.php with the include function.
 
 include('con_members.php');
 
 // Collecting data from a form using variables.
	 $username = $_POST['user'];
	 $password = $_POST['password'];
	 $nickname = $_POST['nick'];
	 $email = $_POST['email'];
		 $fullname = $_POST['fullname'];
 
 //Now for error control, if a requested field is left empty.
 
	 if($username == NULL) { echo "Please fill in Username
 "; }
	 if($password == NULL) { echo "Please fill in Password
 "; }
	 if($nickname == NULL) { echo "Please fill in Nickname
 "; }
	 if($email == NULL) { echo "Please fill in Email"; }
	 if($fullname == NULL) { echo "Please fill in Full Name"; }
 
 //Check if the username or email is in use.
 
	 $userread = mysql_query("SELECT* `username` FROM `members` WHERE `username`='$username'");
	 $user_exist = mysql_num_rows($userread);
 
	 $emailread = mysql_query("SELECT* `email` FROM `members` WHERE `email`='$email'");
	 $email_exist = mysql_num_rows($emailread);
 
	 if ($user_exist>0) { echo "Sorry that username is already in use"; }
	 if ($email_exist>0) { echo "Sorry, that email is already in use"; }
 
	 else {
 
 //If the username doesn't exist, here we insert the information to the table.
 
	 $query = "INSERT INTO members (username, password, email, name, nickname) VALUES('$username','$password','$email','$fullname','$nickname')";
	 mysql_query($query) or die("Sorry, there was a problem in the Database, please try again later.");
 }
 ?>

This is the part of the code I think I am getting the error on...

$userread = mysql_query("SELECT* `username` FROM `members` WHERE `username`='$username'");
	 $user_exist = mysql_num_rows($userread);
 
	 $emailread = mysql_query("SELECT* `email` FROM `members` WHERE `email`='$email'");
	 $email_exist = mysql_num_rows($emailread);


Any help? Thanks. :D

#2 Av-

    I Feel Left Out

  • Members
  • PipPipPipPip
  • 1,971 posts
  • Gender:Male
  • Location:10 ft. below sea level

Posted 22 May 2007 - 05:03 PM

Your query's are messed up

$userread = mysql_query("SELECT username FROM `members` WHERE username = '$username'");
$user_exist = mysql_num_rows($userread);

$emailread = mysql_query("SELECT email FROM `members` WHERE email = '$email'");
$email_exist = mysql_num_rows($emailread);


oh and btw, when dealing with SQL, always call the function 'mysql_error' as it will give you a better insight of what's the problem

print(mysql_error());

Edited by Av-, 22 May 2007 - 05:05 PM.






1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users