|
|
|||||||||
|
|||||||||
|
|||||||||
| |
|||
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Display Modes |
|
#1
|
|||
|
|||
|
help please
Hi i have followed the tutorial creating a membership and i'm having trouble. When i enter my info into the join form i get the following
Notice: Undefined variable: pass in C:\website\register.php on line 70 Your membership information has been mailed to your email address! Please check it and follow the directions! I have globals off. Here is the full script <? include 'db.php'; $first_name = $_POST['first_name']; $last_name = $_POST['last_name']; $email_address = $_POST['email_address']; $username = $_POST['username']; $info = $_POST['info']; $first_name = stripslashes($first_name); $last_name = stripslashes($last_name); $email_address = stripslashes($email_address); $username = stripslashes($username); $info = stripslashes($info); if((!$first_name) || (!$last_name) || (!$email_address) || (!$username)){ echo 'You did not submit the following required information! <br />'; if(!$first_name){ echo "First Name is a required field. Please enter it below.<br />"; } if(!$last_name){ echo "Last Name is a required field. Please enter it below.<br />"; } if(!$email_address){ echo "Email Address is a required field. Please enter it below.<br />"; } if(!$username){ echo "Desired Username is a required field. Please enter it below.<br />"; } include 'join_form.html'; // Show the form again! /* End the error checking and if everything is ok, we'll move on to creating the user account */ exit(); // if the error checking has failed, we'll exit the script! } $sql_email_check = mysql_query("SELECT email_address FROM users WHERE email_address='$email_address'"); $sql_username_check = mysql_query("SELECT username FROM users WHERE username='$username'"); $email_check = mysql_num_rows($sql_email_check); $username_check = mysql_num_rows($sql_username_check); if(($email_check > 0) || ($username_check > 0)){ echo "Please fix the following errors: <br />"; if($email_check > 0){ echo "<strong>Your email address has already been used by another member in our database. Please submit a different Email address!<br />"; unset($email_address); } if($username_check > 0){ echo "The username you have selected has already been used by another member in our database. Please choose a different Username!<br />"; unset($username); } include 'join_form.html'; // Show the form again! exit(); // exit the script so that we do not create this account! } function makeRandomPassword() { $salt = "abchefghjkmnpqrstuvwxyz0123456789"; srand((double)microtime()*1000000); $i = 0; while ($i <= 7) { $num = rand() % 33; $tmp = substr($salt, $num, 1); $pass = $pass . $tmp; $i++; } return $pass; } $random_password = makeRandomPassword(); $db_password = md5($random_password); // Enter info into the Database. $info2 = htmlspecialchars($info); $sql = mysql_query("INSERT INTO users (first_name, last_name, email_address, username, password, info, signup_date) VALUES('$first_name', '$last_name', '$email_address', '$username', '$db_password', '$info2', now())") or die (mysql_error()); if(!$sql){ echo 'There has been an error creating your account. Please contact the webmaster.'; } else { $userid = mysql_insert_id(); // Let's mail the user! $subject = "Your Membership at MyWebsite!"; $message = "Dear $first_name $last_name, Thank you for registering at our website, URL! You are two steps away from logging in and accessing our exclusive members area. To activate your membership, please click here: URL$userid&code=$db_password Once you activate your memebership, you will be able to login with the following information: Username: $username Password: $random_password Thanks! The Webmaster This is an automated response, please do not reply!"; mail($email_address, $subject, $message, "From: FuzionRadio Webmaster<dj.vanes@ntlbusiness.com>\nX-Mailer: PHP/" . phpversion()); echo 'Your membership information has been mailed to your email address! Please check it and follow the directions!'; } ?> |
|
#2
|
|||
|
|||
|
I've been looking over the code, and it seems as though you have a couple of extra braces (it might just be 1, but I'll have to double-check).
PHP Code:
I'm not sure where the matching brace for that is... That could be a causing problem.
__________________
____________________________________________ Developer Shed Weekly Writer | DevArticles Forum Moderator Build Your Own KlipFolio Klip With PHP FrankManno.com - Under Construction Design Interactive Group - Under Construction |
|
#3
|
|||
|
|||
|
In the following function:
Quote:
PHP Code:
PHP Code:
__________________
__________________________________________________ _ Wil Moore III, MCP | Integrations Specialist | Senior Consultant Are You Listed...? | DigitallySmooth Inc. |
|
#4
|
||||
|
||||
|
That's what I was thinking too, laidbak, but PHP isn't strictly typed and doesn't typically require predeclaration of variables, so I ruled it out. Or maybe it's just that this is a log level issue and that most people don't see notices about undeclared variables because the log level's set higher than vanesy's.
|
|
#5
|
|||
|
|||
|
Brilliant it works thanks you guys
|
|
#6
|
|||
|
|||
|
dhouston, yes, you would have been correct had you stated exactly that.
It is indeed a WARNING that is only issued to the screen due to the error log level. It is good to show all Warnings while debugging... makes for more error free code. Browser output can be turned off and this information can be sent to a text file. |
|
#7
|
|||
|
|||
|
Quote:
Laidbak, Wouldn't that keep resetting the value of $pass on each iteration? It would be better to declare $pass outside of the loop, or am I wrong in seeing it that way? |
|
#8
|
|||
|
|||
|
Yes, I assumed he would put the first line outside of the loop...
Its probably bad of me to have assumed such. |
|
#9
|
|||
|
|||
|
Hi all,
I'm having about the same problem. I'm using the same code from the same tutorial. I don't get any error messages, but starting with the characters " 0) || ($username_check > 0)){ echo "Please fix the following errors: "; if($email_check > 0){ echo "Your email address " the whole script shows up on the webpage instead of acting like a script. I've tried everything you said in here, to the best of my ability, but no matter what I do the script breaks into normal text at exactly that point. " 0)" All I know about PHP is what I've taught myself over the last two weeks out of necessity. All things considered, I think I'm doing okay, except that I can't crack this one and I really, really need to. If this sample code is bogus, then can someone point me to a user permissions tutorial w/ code that actually works? Can anyone help me in very simple terms? I still have a lot to learn, but no time for that luxury. Thanks, Yarrielle |
|
#10
|
|||
|
|||
|
Go ahead and post your code, however, please keep in mind the rules of the board before doing so.
|
|
#11
|
|||
|
|||
|
I did read all of the forum rules, and I'm going to try to uphold to them. Just please understand that if I biff up, it's my ignorance and not intentional.
The code is for a user registration form. This entire block is very long, so I'll just post the middle section: PHP Code:
When I view this page, all I see in the browser is Quote:
Except the entire rest of the form is there, too. Nothing before it shows up. I'm positive that I can teach myself how to change the variables if I can just get these snippets to work correctly in the first place. (I guess this part of the code is the validator.) I hope I did that correctly! Thanks, Yarrielle |
|
#12
|
|||
|
|||
|
Try adding another } after the last line you posted.
|
|
#13
|
||||
|
||||
|
I'd guess you've got a stray "<" somewhere near the top of your code and that for some reason, the code between that and the ">" in the line that's printing is being interpreted as an HTML tag. I'd wager also that you're running on Windows and that this oddity results in part from bugginess on that platform. Just a guess.
|
|
#14
|
|||
|
|||
|
Thanks, Laidbak, but no go. I tried what I'm sure you meant, then I tried many different variations in case I had it wrong, but nothing worked. The script still breaks into text at the same point. I appreciate your looking, though!
|