chriscloyd Posted March 27, 2007 Share Posted March 27, 2007 <?php include("config.php"); //check required fileds //username password c_password email c_email if ($_POST['username'] == '') { $error = '1'; $reason = '-You did not submit a username.'; } if ($_POST['password'] == '') { $error = '1'; $reason = '-You did not submit a password.'; } if ($_POST['c_password'] == '') { $error = '1'; $reason = '-You did not submit a email address.'; } if ($_POST['email'] == '') { $error = '1'; $reason = '-You did not submit a password.'; } if ($_POST['c_email'] == '') { $error = '1'; $reason = '-You did not submit a confirmation email address.'; } if ($error) { //return to register page and display reasons } ?> say if they did not fill in any of those fields I want to go back and show all the errors when i do it, it was only showin 1 error Quote Link to comment Share on other sites More sharing options...
per1os Posted March 27, 2007 Share Posted March 27, 2007 <?php include("config.php"); //check required fileds //username password c_password email c_email if ($_POST['username'] == '') { $error = '1'; $reason .= '-You did not submit a username.'; } if ($_POST['password'] == '') { $error = '1'; $reason .= '-You did not submit a password.'; } if ($_POST['c_password'] == '') { $error = '1'; $reason .= '-You did not submit a email address.'; } if ($_POST['email'] == '') { $error = '1'; $reason .= '-You did not submit a password.'; } if ($_POST['c_email'] == '') { $error = '1'; $reason .= '-You did not submit a confirmation email address.'; } if ($error) { //return to register page and display reasons } ?> use .= to append to the current string. That should work. Quote Link to comment Share on other sites More sharing options...
chriscloyd Posted March 27, 2007 Author Share Posted March 27, 2007 should i put <br> after then too to make new line Quote Link to comment Share on other sites More sharing options...
kenrbnsn Posted March 27, 2007 Share Posted March 27, 2007 If the OP does it that way all the messages end up on one line. To get them on separate lines, try something like this: <?php include("config.php"); $reason = array(); //check required fileds //username password c_password email c_email if ($_POST['username'] == '') { $reason[] = '-You did not submit a username.'; } if ($_POST['password'] == '') { $reason[] = '-You did not submit a password.'; } if ($_POST['c_password'] == '') { $reason[] = '-You did not submit a email address.'; } if ($_POST['email'] == '') { $reason[] = '-You did not submit a password.'; } if ($_POST['c_email'] == '') { $reason[] = '-You did not submit a confirmation email address.'; } if (!empty($reason)) { echo 'The following errors were detected:<br>' . implode("<br>\n",$reason) . "<br>\n"); // shows how to display the messages //return to register page and display reasons } ?> You'll notice that you don't need a "error" flag with this method, just check to see if the array is empty or not. Ken Quote Link to comment Share on other sites More sharing options...
chriscloyd Posted March 27, 2007 Author Share Posted March 27, 2007 When i do that its showing all the errors go here http://www.chaoslegionclan.net/CEGL-Work/newsite/index.php?p=register and try to fill in just the user name it comes back with all the errors not just the password c-password email and c-email Quote Link to comment Share on other sites More sharing options...
per1os Posted March 27, 2007 Share Posted March 27, 2007 Can we see the form? Meaning post the form code, thanks. Quote Link to comment Share on other sites More sharing options...
chriscloyd Posted March 27, 2007 Author Share Posted March 27, 2007 http://www.chaoslegionclan.net/CEGL-Work/newsite/index.php?p=register yes that link i showed u shows you the form even when i eneter info into the required ones which r username password confirm password email confirm email i still get the errors heres my updated code <?php include("config.php"); //check required fileds //username password c_password email c_email $reason = array(); $username = $_POST['username']; $password = $_POST['password']; $c_password = $_POST['c_password']; $email = $_POST['email']; $c_email = $_POST['c_email']; if (empty($username)) { $reason[] = '-You did not submit a username.'; } if (empty($password)) { $reason[] = '-You did not submit a password.'; } if (empty($c_password)) { $reason[] = '-You did not submit a email address.'; } if (empty($email)) { $reason[] = '-You did not submit a password.'; } if (empty($c_email)) { $reason[] = '-You did not submit a confirmation email address.'; } if (!empty($reason)) { $reasons = implode("<br>",$reason); header("Location: ../index.php?p=register&error=".$reasons); } ?> Quote Link to comment Share on other sites More sharing options...
per1os Posted March 27, 2007 Share Posted March 27, 2007 That page 404's which is why I requested for the code to be pasted on here for the form. Quote Link to comment Share on other sites More sharing options...
chriscloyd Posted March 27, 2007 Author Share Posted March 27, 2007 try the link again i edited it http://www.chaoslegionclan.net/CEGL-Work/newsite/index.php?p=register Quote Link to comment Share on other sites More sharing options...
per1os Posted March 27, 2007 Share Posted March 27, 2007 <form action="files/process_register.php" method="get"> That is your issue, you are using POST, change the above to: <form action="files/process_register.php" method="POST"> and it should work. Quote Link to comment Share on other sites More sharing options...
chriscloyd Posted March 27, 2007 Author Share Posted March 27, 2007 omfg lol hehe thanks Quote Link to comment Share on other sites More sharing options...
yzerman Posted March 27, 2007 Share Posted March 27, 2007 Why not do this: if (isset($_POST['username'])) { $username = $_POST['username']; } else { $username = NULL; } if (isset($_POST['password']) && isset($_POST'c_password'])) { //if password and conformation is set if ($_POST['password'] == $_POST['c_password'])) { //if pass 1 matches pass 2 $password = $_POST['password']; //set the password variable } else { // passwords do not match $password = NULL } } else { // password or conformation is blank $password = NULL; } if (isset($_POST['email'])) { $email = $_POST['email']; } else { $email = NULL; } if ($username && $email && $password) { //if the variables are set //register the user } else { //variables arent set, lets echo an error message for the ones not set if ($username == NULL) { echo 'You must enter a username!'; } if ($password == NULL) { echo 'Your passwords do not match 100%. Please go back and confirm your password.!'; } if ($email == NULL) { echo 'You must enter valid email address!'; } Quote Link to comment 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.