Contact Us Forum Rules Search Archive
WebProWorld Part of WebProNews.com
Page One Link To Us Edit Profile Private Messages Archives FAQ RSS Feeds  
 

Go Back   WebProWorld > Webmaster, IT and Security Discussion > Web Programming Discussion Forum
Subscribe to the Newsletter FREE!


Register FAQ Members List Calendar Arcade Chatbox Mark Forums Read

Web Programming Discussion Forum Working with an API? Developing a plugin? Writing a Mod or script for your favorite blog, Web 2.0 site or Forum? Welcome.

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 06-06-2005, 10:29 PM
WebProWorld New Member
 

Join Date: Apr 2005
Location: NY
Posts: 14
ccpadmin RepRank 0
Default registration script PHP

I am getting an error message that I cant figure out...

Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in C:\xampplite\htdocs\xampp\al\feteconnect\register2 .php on line 81

Can anyone explain where I am going wrong? I tried searching for help and other code...

Code:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>Register for Feteconnect</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<link href="css/l2.css" rel="stylesheet" type="text/css">
</head>

<body>
<?php 
include("inc/header.php");
?>
<div id="middle">
<?php 
if (isset($_POST['reg'])){

require_once("inc/sql_connect.php");

$message = NULL;

if (empty($_POST['fname'])){
	$message .= 'The first name must be between 0-20 letters long.
';
	$fname = FALSE;
} else {
	$fname = ($_POST['fname']);
}

if (empty($_POST['lname'])){
	$message .= 'The last name must be between 0-20 letters long.
';
	$lname = FALSE;		
} else {
	$lname = ($_POST['lname']);
}

if (empty($_POST['email'])){
	$message .= 'The email address must be between 0-40 letters long.
';
	$email = FALSE;
} else {
	$email = ($_POST['email']);
}

if(empty($_POST['registered_as'])){
	$message .= 'Please select a registration type.
';
	$registered_as = FALSE;
	}

if(empty($_POST['username'])) {
	$message .= 'Please enter your username.
';
	$username = FALSE;
	}

if((empty($_POST['pass']))||(empty($_POST['conf']))){
	$message .= 'Please enter your password in both fields.
';
	$pass = FALSE;
	}		

if(($_POST['pass'])==($_POST['conf'])){
	$pass = ($_POST['pass']);
	if(strlen($_POST['pass']) < 8) {
		$message .= 'For your security, your password has to be at least eight(8) characaters long.
';
		$pass = FALSE;
		}
} else {
	$message .= 'The password has not been confirmed. Make sure they match!
';
	$pass = FALSE;
}
	
if($_POST['registered_as']=='dj') $registered_as='dj';
if($_POST['registered_as']=='dncr') $registered_as='dncr';
if($_POST['registered_as']=='mdl') $registered_as='mdl';
if($_POST['registered_as']=='pro') $registered_as='pro';	
	
echo $message;

if($fname && $lname && $email && $registered_as && $username && $pass) {

	//make sure the username is available
	$query = "SELECT user_id FROM users WHERE username='$username'";
	$result = @mysql_query ($query);
	
	if (mysql_num_rows($result)==0) {
	
		// Add the user
		$query = "INSERT INTO users(pass, registered_as, fname, lname, email, registration_date)
		VALUES (PASSWORD('$pass'), '$registered_as', '$fname', '$lname', '$email', NOW() )";
		$result = @mysql_query($query);
		
		if ($result) {
		
			echo '

Thanks for registering! 

 Your registration information is as follows:
';
			echo "$fname
";
			echo "$lname
";
			echo "$email
";
			echo "$registered_as
";
			echo "$pass</p>";
			include("inc/footer.php");
			exit();
		} else {
			echo '

You could not be registered due to a system error. We apologize for any inconvenience.</p>';
			}
			
	} else {
		echo '

That username is not available</p>';
	}
	mysql_close();//close the db
} else {
	echo '

Please try again later.</p>';
}
}else {
?>


Enter your registration info in the form below. Don't forget to select your Registration type!</p>
<form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post">
<table width="100%" >
  <tr>
    <td><div align="right">First name:</div></td>
    <td><input name="fname" type="text" size="25" maxlength="20"></td>
  </tr>
  <tr>  
    <td><div align="right">Last name:</div></td>
    <td><input name="lname" type="text" size="25" maxlength="20"></td>	
  </tr>
  <tr>
    <td><div align="right">Email:</div></td>
    <td><input type="text" size="30" name="email" maxlength="40"></td>
  </tr>
  <tr>
    <td><div align="right">Registered As:</div></td>
    <td><select name="registered_as">
		 <option value="">Select One</option>
		 <option value="dj">DJ</option>
		 <option value="dncr">Dancer</option>
		 <option value="mdl">Model</option>
		 <option value="pro">Promoter</option>
	</select>
  </tr>
  <tr>
    <td><div align="right">User Name:</div></td>
    <td><input type="text" size="30" name="username" maxlength="25"></td>
  </tr>
  <tr>
    <td><div align="right">Password:</div></td>
    <td><input type="text" size="15" name="pass" maxlength="12"></td>
  </tr>
  <tr>
    <td><div align="right">Confirm Password:</div></td>
    <td><input type="text" size="15" name="conf" maxlength="12"></td>
  </tr>
  <tr>
    <td></td>
    <td><input type="reset" name="reset" value="Clear Form">
		<input type="submit" name="reg" value="Register"></td>
  </tr>
</table>

</form>
<?php 
}
include("inc/footer.php");
?>
</div>
__________________
$PHP_rocks = TRUE;
Reply With Quote
  #2 (permalink)  
Old 06-07-2005, 12:03 AM
mushroom's Avatar
WebProWorld Veteran
 

Join Date: Feb 2004
Location: Queen Charlotte B. C. Canada
Posts: 351
mushroom RepRank 0
Default

Quote:
Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in
Check the query that feeds it, when the query fails that is what you see.

Even when the query returns no rows the value is 0 and is a valid result, only Bad query will give that error.
__________________
Irony: That for most people the most "trusted" web site on the planet is for a company the has been convicted of criminal activity.

Both Security and SuSe start with "S". www.oldslides.com
Reply With Quote
  #3 (permalink)  
Old 06-09-2005, 02:20 PM
WebProWorld New Member
 

Join Date: Apr 2005
Location: NY
Posts: 14
ccpadmin RepRank 0
Default rewrote the script

I took out the check for the previously registered username and I am now getting a weird error regarding the host, username, db data in my included sqlconnect file.

Everything has been going great up to this point with my site and I would like to get it up but this is pushing the launch date back a bit. It is an integral part of the site too. Functionality for only registered members and all...

I guess I have to comb this code with a fine tooth and compare it to other code and see the techniques that other programmers are using to validate new users and register them.

thanks anyway.
__________________
$PHP_rocks = TRUE;
Reply With Quote
  #4 (permalink)  
Old 06-15-2005, 08:23 AM
WebProWorld New Member
 

Join Date: Jun 2005
Location: Malta
Posts: 1
szc001 RepRank 0
Default Re: registration script PHP

I am presuming that your mysql_connect call is in your inc/sql_connect.php file...

This is always required if you are going to call any mysql method.

Therefore, your problem is probably that the table users doesn't exist, or maybe you are forgetting to select the database you are working in beforehand using mysql_select_db

Alternatively you can bypass selecting the database beforehand (i.e. if you don't want to touch your sql_connect file and call the table directly using the dbname.tablename syntax.

i.e. if your users table falls under, let's say, the mydata schema, your command would read:

Code:
SELECT users.user_id FROM mydata.users WHERE username='{$username}'
hope i was of help... if that doesn't work... kindly paste your sql_connect file here also.

Note: I always like fully qualifying field names, since it makes life easier should you want to build the query further in the future, and it avoids stupid mistakes where field names could conflict with keywords.
__________________
- szc001
- www.szc001.com
- szc001(@)gmail(.)com
Reply With Quote
Reply

  WebProWorld > Webmaster, IT and Security Discussion > Web Programming Discussion Forum
Tags: , ,



Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Search Engine Optimization by vBSEO 3.2.0