Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

PHP Forum


You are currently viewing our PHP Forum as a guest. Please register to participate.
Login



Freelance Jobs

Reply
Old 06-06-2005, 10:35 PM log in script error
ccp
ccp's Avatar
Average Talker

Posts: 28
Trades: 0
I keep getting this error:

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

I don't know what to change the value to. I tried using '' since the variable that I was checking for in the db was text. I was first checking for just the user name then I added the user_id field to the table and checked for 0 which I guess would never occur. I have been working on this all day.

Besides this can someone point me to a pdf or something that concisely covers php. Part of what is slowing me down in my progress with PHP/MySQL is having the Visual Quickstart books for both and I am more or less beyond those.

Here is the (full) 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.<br>';
	$fname = FALSE;
} else {
	$fname = ($_POST['fname']);
}

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

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

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

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

if((empty($_POST['pass']))||(empty($_POST['conf']))){
	$message .= 'Please enter your password in both fields.<br>';
	$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.<br>';
		$pass = FALSE;
		}
} else {
	$message .= 'The password has not been confirmed. Make sure they match!<br>';
	$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 '<p>Thanks for registering! <br><br> Your registration information is as follows:<br>';
			echo "$fname<br>";
			echo "$lname<br>";
			echo "$email<br>";
			echo "$registered_as<br>";
			echo "$pass</p>";
			include("inc/footer.php");
			exit();
		} else {
			echo '<p>You could not be registered due to a system error. We apologize for any inconvenience.</p>';
			}
			
	} else {
		echo '<p>That username is not available</p>';
	}
	mysql_close();//close the db
} else {
	echo '<p>Please try again later.</p>';
}
}else {
?>
<p>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>&nbsp;</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>
ccp is offline
Reply With Quote
View Public Profile
 
 
Register now for full access!
Old 06-07-2005, 03:58 AM
0beron's Avatar
Defies a Status

Posts: 1,832
Location: Somewhere else entirely
Trades: 0
Try putting an or die() on the end of your sql query ( the one that generates $result ready for line 81 ):

$result = mysql_query("your query") or die(mysql_error());

That should echo back any sql errors you may have. Once you fix the problem you can drop the or die and go back to silent mode (@mysql_query)
__________________
UPDATE 0beron SET talkupation = talkupation + lots WHERE post = 'helpful';

Please login or register to view this content. Registration is FREE
(aka MSN handwriting for forums)
0beron is offline
Reply With Quote
View Public Profile Visit 0beron's homepage!
 
Old 06-07-2005, 10:06 AM
leavethisplace's Avatar
Ultra Talker

Posts: 297
Trades: 0
for a start, line 81 is
PHP Code:
if (mysql_num_rows($result)==0) { 
i believe. The two lines above need to be changed
PHP Code:
//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) { 
And do what oberon said, u should always have a die() after the query, something like
PHP Code:
or die("SQL ERROR " mysql_error()); 
__________________
A lie gets halfway around the world before the truth has a chance to get its pants on. - Sir Winston Churchill

Please visit my sites:
Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
leavethisplace is offline
Reply With Quote
View Public Profile
 
Old 06-09-2005, 02:22 PM
ccp
ccp's Avatar
Average Talker

Posts: 28
Trades: 0
thanks for the tips. I will try this and get back tonight...I have been racking my brain about this for a good bit.
ccp is offline
Reply With Quote
View Public Profile
 
Old 06-11-2005, 09:12 PM
ccp
ccp's Avatar
Average Talker

Posts: 28
Trades: 0
Your tips worked thanks for the help.

I rewrote the script without the username validation, maybe unnecessary but I thought I might think of something that I forgot. Everything works perfect now.

I got it to add a user to the database last night. I had a lil problem because the username was unique in the db and I wasn't entering it with the query. So it didn't add more than one user. A quick change to the query fixed that.

Then I wanted to validate the username against the db to see if it was previously used. That worked perfectly too after a lil debugging. It now prints a message on successful registration and if the username is taken already, and any other errors.


I was thinking of validating the email address to make sure no one enters the same email twice in the db. But that seemed to be redundant. What two people will register with the same email?


Anyway, Thanks for your help.

Now I have to tackle the login script and what to do on successful login, cookie or session, redirect, etc.
ccp is offline
Reply With Quote
View Public Profile
 
Old 06-12-2005, 07:38 PM
leavethisplace's Avatar
Ultra Talker

Posts: 297
Trades: 0
you should only restrict the email address duplication if you want to try and stop one person having like 3 or more accounts - but then again people can just create new email accounts bla bla bla...
__________________
A lie gets halfway around the world before the truth has a chance to get its pants on. - Sir Winston Churchill

Please visit my sites:
Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
leavethisplace is offline
Reply With Quote
View Public Profile
 
Old 06-13-2005, 03:11 AM
ccp
ccp's Avatar
Average Talker

Posts: 28
Trades: 0
well hopefully the fact that you may (still debating that) have to pay to register will be enough of a deterrent of registering more than once.
ccp is offline
Reply With Quote
View Public Profile
 
Reply     « Reply to log in script error
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

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

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





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 0.67277 seconds with 12 queries