Hi,
My forms validation is on the same page as the form itself, so when the user hits ‘Submit’ it reloads the page and checks through the validation code. If everything is OK it then sends the user to a second page, where the data is added to the MySql table.
However, I am having some trouble with getting the $_POST data to the second page after the first page has already used it.
Is there something different I need to do to send the data to the second page if I am already using it on the first page?
Or is there a better way of achieving what I am trying to do?
Here is my PHP code:
[php]<?php
if (isset($_POST[‘username’], $_POST[‘realname’], $_POST[‘password’], $_POST[‘repassword’], $_POST[‘email’]))
{
$errors = array();
$username = $_POST['username'];
$realname = $_POST['realname'];
$password = $_POST['password'];
$repassword = $_POST['repassword'];
$email = $_POST['email'];
if (empty($username) || empty($realname) || empty($password) || empty($repassword)|| empty($email))
{
$errors[] = 'All fields are required';
}
else
{
if(strlen($username) > 25 ) $errors[] = '• Username can not be longer than 12 characters';
if(strlen($username) < 3 ) $errors[] = '• Username must be 3 characters or more';
if(preg_match(’/[^0-9A-Za-z]/’,$username)) $errors[] = ‘•asdfadfafadfadfadsf’;
if(strlen($realname) < 2 ) $errors[] = ‘• Real name can not be shorter than 2 characters’;
if(strlen($password) < 5 ) $errors[] = ‘• Password must be 5 characters or more’;
if($password !== $repassword) $errors[] = ‘• Passwords do not match’;
if(filter_var($email, FILTER_VALIDATE_EMAIL) === FALSE) $errors[] = ‘• Please enter a valid email address’;
}
if(!empty($errors))
{
foreach($errors as $error)
{
}
}
else
{
header(“Location: adduser.php”);
}
}
?>
Thank you