bobby317 Posted May 4, 2010 Share Posted May 4, 2010 Ok it is me again I have reworked my script some and have run into a problem. I have the code working so far to validate the form when submitted and also if the for submit is successful the form will go away and you will get an you have registered message. I am thinking I can use cookies with another if else statement to have the form show when you first visit the page. The problem now is that the code that prints the form only prints when the form is submitted. I placed it the way I did so it would not stay there if the registration was a success. Any help suggestion appreciated. And please explain what you are doing thanks. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>Register</title> <style type="text/css"> body { text-align: center; } form { text-align: left; } label { width: 7em; float: left; text-align: right; margin-right: 0.5em; } .submit input { margin-left: 6.5em; } .error { color: #F00; } </style> </head> <body> <?php //Starts the code when form is submitted: if( isset($_POST['submit'])){ //flag variable to track success: $okay = TRUE; //Validate the email address: if (empty($_POST['email1'])) { print '<p class="error">Please enter your email.</p>'; $okay = FALSE; } //Validate the password: if (empty($_POST['pass1'])) { print '<p class="error">Please enter your password.</p>'; $okay = FALSE; } //validate the emails for equality: if ($_POST['email1'] != $_POST['email2']) { print '<p class="error">Your emails do not match.</p>'; $okay = FALSE; } //Validate the passwords for equality: if ($_POST['pass1'] != $_POST['pass2']) { print '<p class="error">Your passwords do not match.</p>'; $okay = FALSE; } //If there were no errors, print a success message: if ($okay) { print'<p>You have been successfully registered.</p>'; } else { print' <form name="register" action="register.php" method="post"> <p> <label for="email1">Email Adress:</label> <input type="text" name="email1" maxlength="30" /> </p> <p> <label for="email2">Email Adress Again:</label> <input type="text" name="email2" maxlength="30" /> </p> <p> <label for"password">Password:</label> <input type="password" name="pass1" /> </p> <p> <label for"password2">Password Again:</label> <input type="password" name="pass2" /> </p> <p class="submit"> <input type="submit" value="Register" /> <input type="hidden" name="submit" value="true" /> </p> </form>'; } } ?> </body> </html> Quote Link to comment https://forums.phpfreaks.com/topic/200620-beginner-creating-a-user-registration-page/ Share on other sites More sharing options...
PFMaBiSmAd Posted May 4, 2010 Share Posted May 4, 2010 You need to post your code between the forum's or tags. See the or buttons in the forum's menu to put the or tags around selected text when you are writing your post. Quote Link to comment https://forums.phpfreaks.com/topic/200620-beginner-creating-a-user-registration-page/#findComment-1052808 Share on other sites More sharing options...
Muddy_Funster Posted May 4, 2010 Share Posted May 4, 2010 ok, here we go: fistly have removed the form from the page and put it in form.php (doesnt need to be .php, you can make it .htm or .inc or whatever) <form name="register" action="register.php?submit=\'true\'" method="post"> <p> <label for="email1">Email Adress:</label> <input type="text" name="email1" maxlength="30" /> </p> <p> <label for="email2">Email Adress Again:</label> <input type="text" name="email2" maxlength="30" /> </p> <p> <label for"password">Password:</label> <input type="password" name="pass1" /> </p> <p> <label for"password2">Password Again:</label> <input type="password" name="pass2" /> </p> <p class="submit"> <input type="submit" value="Register" /> <input type="hidden" name="submit" value="true" /> </p> </form>' then changed your logic to do a negative check on the isset (and pulled your hidden field, but you can put that back in if you preffer). then set your nested if's as ifelse to lighten the run through (it will now error out per field rather than all at once, but again you can put this back to if's if you preffer) the only thing that changed the actual behaviour was changeing it from if(isset()) to if(!isset()). Quote Link to comment https://forums.phpfreaks.com/topic/200620-beginner-creating-a-user-registration-page/#findComment-1052919 Share on other sites More sharing options...
Muddy_Funster Posted May 4, 2010 Share Posted May 4, 2010 oops, forgot to post the edited code [duh] <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>Register</title> <style type="text/css"> body { text-align: center; } form { text-align: left; } label { width: 7em; float: left; text-align: right; margin-right: 0.5em; } .submit input { margin-left: 6.5em; } .error { color: #F00; } </style> </head> <body> <?php //Starts the code when form is submitted: if( !isset($_GET['submit'])){ //changed logic about to check registration negativly include_once "form.php"; } else { //flag variable to track success: $okay = TRUE; //Validate the email address: if (empty($_POST['email1'])) { print '<p class="error">Please enter your email.</p>'; $okay = FALSE; include_once "form.php"; } //Validate the password: elseif (empty($_POST['pass1'])) { print '<p class="error">Please enter your password.</p>'; $okay = FALSE; include_once "form.php"; } //validate the emails for equality: elseif ($_POST['email1'] != $_POST['email2']) { print '<p class="error">Your emails do not match.</p>'; $okay = FALSE; include_once "form.php"; } //Validate the passwords for equality: elseif ($_POST['pass1'] != $_POST['pass2']) { print '<p class="error">Your passwords do not match.</p>'; $okay = FALSE; include_once "form.php"; } //If there were no errors, print a success message: elseif ($okay == TRUE) { print'<p>You have been successfully registered.</p>'; } } ?> </body> </html> Quote Link to comment https://forums.phpfreaks.com/topic/200620-beginner-creating-a-user-registration-page/#findComment-1052920 Share on other sites More sharing options...
nhojeinnor Posted May 4, 2010 Share Posted May 4, 2010 <?php //ur post value here. $username=$_POST['username'] ?> <tr><td><font face="neuropol" size="2">*Username:</font></td><td><input type="text" name ="username" size="21" value="<?php echo $username ?>"></td> <?php if(isset($_POST['submit']) and !empty($_POST['username'])) { include "connect.php"; $queryID = mysql_query("SELECT username FROM cus_reg WHERE username ='$username'"); $countRecord = mysql_num_rows($queryID); if($countRecord != 0) { die("<td><font color=#990000 size=-1>Username already Exist.<meta http-equiv='refresh' content='2,URL=customer_reg.php'></font></td>"); $adderror.=""; } else { echo""; } } if(isset($_POST['submit']) and empty($username)) { echo "<td><font color=#990000 size=-1 face=neuropol>*Enter First Name.</font></td>"; $adderror.="error"; } elseif(isset($_POST['submit']) and strlen($username) < 5) { echo "<td><font color=#990000 size=-1 face=neuropol>*Minimum of 5 Characters Only.</font></td>"; $adderror.="error"; } else { echo""; } ?> </tr> <tr><td><br><font face="neuropol" size="2">*Password:</font></td><td><br><input type="password" name ="password" size="21"></td> <?php if(isset($_POST['submit']) and empty($password)) { echo "<td><br><font color=#990000 size=-1 face=neuropol>*Enter Password.</font></td>"; $adderror.="error"; } elseif(isset($_POST['submit']) and strlen($password) < 7) { echo "<td><br><font color=#990000 size=-1 face=neuropol>*Minimum of 7 Characters Only.</font></td>"; $adderror.="error"; } else if(isset($_POST['submit']) and ($password != $repeat)) { echo "<td><br><font color=#990000 size=-1 face=neuropol>*Password did not Match.</font></td>"; $adderror.="error"; } else echo ""; ?> </tr> </tr> <tr><td><br><font face='neuropol' size='2'>*Repeat Password:</font></td> <td><br><font face='neuropol' size='2'><input type="password" name ="repeat" size="21"></font></td> <?php if(isset($_POST['submit']) and empty($repeat)) { echo"<td><br><font color=#990000 size=-1 face=neuropol>*Enter Password</font></td>"; $adderror.="error"; } else if(isset($_POST['submit']) and ($password != $repeat)) { echo "<td><br><font color=#990000 size=-1 face=neuropol>*Password did not Match.</font></td>"; $adderror.="error"; } else { echo ""; } ?> </tr> <tr><td><br><br></td><td><br><input type="submit" value="Create Account" name="submit"><br><br><a href ="tellerpage.php"><font face=neuropol size=2>Back</font></a></td></tr> <?php if((isset($_POST['submit'])) and empty($adderror)) { include "connect.php"; $queryreg = mysql_query (" //your mysql query here. INSERT blablabla. "); mysql_error(); die("Registration Successful,<br>") } else if(!empty($adderror)) { echo"<center><br>Please FIll in The Required Fields</center><br><br><br>"; $adderror .= "error"; } ?> here's an example.. try this one.. Quote Link to comment https://forums.phpfreaks.com/topic/200620-beginner-creating-a-user-registration-page/#findComment-1052922 Share on other sites More sharing options...
bobby317 Posted May 4, 2010 Author Share Posted May 4, 2010 Thanks again muddy it work's perfectly. Quote Link to comment https://forums.phpfreaks.com/topic/200620-beginner-creating-a-user-registration-page/#findComment-1053232 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.