registration submit button dont work also w/ variable error

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
x
Forum Newbie
Posts: 12
Joined: Wed Jun 08, 2005 11:31 pm

registration submit button dont work also w/ variable error

Post by x »

a simple registration form
when i load this from a web page, it does nothing when i press the submit button. i tried to use it at home on a winxp pro w/ php-5 and mysql and i edited the php.ini file
so i could see more errors (i unquote the line thats shows all kinds of errors and notification) then i saw it has some unidentified variable error on some lines.
edit: i also turned on the register globals to make sure but it still dont work

Code: Select all

<?php 



if(isset($_POST['submit'])){
			   //handle the form.
			   $submit = $_POST['submit'];
			   $message = NULL; //create a variable

	                   //check for a username
			   if (empty($_POST['username']))
					{$un = FALSE;
		
					$message .= '<p>You forgot to enter your user name</p>';
			
                			}else{  
					       $un = $POST['username'];
					     }

			//check for a password and match against the confirmed password
			if (empty($_POST['password1']))
					{$p = FALSE;

					$message .= '<p>You forgot to enter a password!</p>';
			
					}else{	
		
						if ($_POST['password1'] == $_POST['password2'])
					     		{$pw = $POST['password1'];
							}else{
								$pw=FALSE;
								$message .= '<p>Your password did not match the confirmed password!</p>';
								}
						}
			//check for a email
			if (empty($_POST['email']))
					{$em = FALSE;
					$message .= '<p>You forgot to enter your email</p>';
			
                			}else{  
						$em = $POST['email'];
					}




	if($un && $pw && $em)
		{//if the three inputs have value
		require_once('/mysql_connect.php'); //connect to database
		$query = "INSERT INTO forum_users (u_nick, u_password, u_email, u_date) VALUES ('$un',PASSWORD('$pw'),'$em','NOW())";
		$result = @mysql_query($query); //run the query	

			if($result) {//if it ran ok
					echo '<p>You are now registered.</p>';
					exit();
					}else{//something is missing
						$message = '<p>error</p><p>'.mysql_error().'</p>';
						}
		mysql_close();
		}else{ $message .='<p>Please try again.</p>';
			echo('$un' . "$un");
		     }
		}


if(isset($message)){
 echo '<font color="red">',$message,'</font>';
}

?>

<form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post">
<fieldset><legend>ENTER YOUR INFORMATION IN THE FORM BELOW:</legend>

<p><b>User Name:</b> <input type="text" name="username" size="15" maxlength="15" 
value="<?php if(isset($_POST['username'])) echo $POST['username'];?>"/></p>

<p><b>Password:</b> <input type="password" name="password1" size="20" maxlength="40" 
value="<?php if(isset($_POST['password1'])) echo $POST['password1'];?>"/></p>

<p><b>Confirm Password:</b> <input type="password" name="password2" size="20" maxlength="40" 
value="<?php if(isset($_POST['password2'])) echo $POST['password2'];?>"/></p>

<p><b>Email Address:</b> <input type="text" name="email" size="40" maxlength="60" 
value="<?php if(isset($_POST['email'])) echo $POST['email'];?>"/></p>

</fieldset>
<div align="center"><input type="submit" name="submit" value="Register"/>
</div>
</form>
User avatar
patrikG
DevNet Master
Posts: 4235
Joined: Thu Aug 15, 2002 5:53 am
Location: Sussex, UK

Post by patrikG »

moved to PHP - Code
User avatar
phpScott
DevNet Resident
Posts: 1206
Joined: Wed Oct 09, 2002 6:51 pm
Location: Keele, U.K.

Post by phpScott »

great post those line numbers so we don't have to try and read through the whole code.
Cheers :D
User avatar
x
Forum Newbie
Posts: 12
Joined: Wed Jun 08, 2005 11:31 pm

fixed

Post by x »

thanks phpscott, the lines that have variable errors are the ones linking to the html "post". like this one $un = $POST['username'];
i fixed it by just placing another $un = $POST['username']; at the start of the page before the isset().

im just wondering why they dont work now, i think im using this kind of coding before and i cant remember having the need to initialize the variable. do you guys know why??

btw sorry for posting in the wrong forum
User avatar
phpScott
DevNet Resident
Posts: 1206
Joined: Wed Oct 09, 2002 6:51 pm
Location: Keele, U.K.

Post by phpScott »

just because $_POST['submit'] is set doesn't mean all the others are.
the way I do it is

Code: Select all

if(isset($_POST['username']) && $_POST['username'] !='')
first checks to make sure $_POST['username'] is set and then test to make sure it isn't empty.
Post Reply