Snooble Posted July 17, 2007 Share Posted July 17, 2007 Hello everyone... I'm almost there. I have 2 pages... one shows the register form, one is the check form. I want to have 2 pages... not one... heres the checkregister.php page <?php $errors = array(); if (empty($_POST['username'])) { $errors[] = 'Please supply a username'; } if (empty($_POST['password']) || strlen($_POST['password']) < 6) { $errors[] = 'You entered an invalid password'; } if (empty($_POST['email']) || strpos($_POST['email'], '@') === false) { $errors[] = 'You entered an invalid email'; } $check = "SELECT * FROM wmusers where username='".$_POST['username']."' LIMIT 1"; $checkresult = mysql_query($check); if (mysql_num_rows($checkresult) != 0) { $errors[] = 'You entered a taken username'; } $check2 = "SELECT * FROM wmusers where email='".$_POST['email']."' LIMIT 1"; $checkresult2 = mysql_query($check2); if (mysql_num_rows($checkresult2) != 0) { $errors[] = 'You entered a taken email'; } $_SESSION['errors'] = $errors[]; if (count($errors)) { header("Location: register.php"); exit; } else { $sql = "INSERT INTO wmusers VALUES ('0', '".$_POST['username']."', '".$_POST['password']."', '".$_POST['email']."', '0')"; mysql_query($sql) or die ("Couldn't execute $sql: " . mysql_error()); } ?> I need it to send the errors back to register.php how will i save them and output them on register.php... until they're all correct then it continues to the complete. Make sense? at the moment i cant get it to output the data to the first page when it header's. Thanks Snooble Quote Link to comment Share on other sites More sharing options...
Snooble Posted July 17, 2007 Author Share Posted July 17, 2007 <?php $errors = array(); if (empty($_POST['username'])) { $errors[] = 'Please supply a username'; } if (empty($_POST['password']) || strlen($_POST['password']) < 6) { $errors[] = 'You entered an invalid password'; } if (empty($_POST['email']) || strpos($_POST['email'], '@') === false) { $errors[] = 'You entered an invalid email'; } $check = "SELECT * FROM wmusers where username='".$_POST['username']."' LIMIT 1"; $checkresult = mysql_query($check); if (mysql_num_rows($checkresult) != 0) { $errors[] = 'You entered a taken username'; } $check2 = "SELECT * FROM wmusers where email='".$_POST['email']."' LIMIT 1"; $checkresult2 = mysql_query($check2); if (mysql_num_rows($checkresult2) != 0) { $errors[] = 'You entered a taken email'; } if (count($errors)) { header("Location: register.php"); exit; } else { $sql = "INSERT INTO wmusers VALUES ('0', '".$_POST['username']."', '".$_POST['password']."', '".$_POST['email']."', '0')"; mysql_query($sql) or die ("Couldn't execute $sql: " . mysql_error()); } ?> EDIT I need to know how to echo out the array of errors Snooble Quote Link to comment Share on other sites More sharing options...
fanfavorite Posted July 17, 2007 Share Posted July 17, 2007 To pass variables to another page, include the page rather than redirect to another page. For example: include ('register.php') die; //makes the current pages script stop, when the register is included Now in the register.php page you can use the $error variables. 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.