I need help with my PHP form validation as it isn’t showing they have been successful registering and also errors not showing if they don’t enter email etc. There it is. If there is a better solution you can tell me i will be very happy Thanks
<?php //arrays $errors_M = array(); $cleans = array(); //checks submit if (isset($_POST['submit']) && $_POST['submit'] != 'Logout') { $_POST['First Name'] = (isset($_POST['First Name']) ? trim($_POST['First Name']) : ''); // only allowed alphanumeric characters $nospaces = str_replace(' ', '', $_POST['First Name']); if($_POST['First Name'] != '' && ctype_alpha) { $cleans['First Name'] = $_POST['First Name']; } else { $errors_M[] = 'First Name is required with alphanumeric characters.'; } // alphabet characters only $_POST['Last Name'] = (isset($_POST['Last Name']) ? trim($_POST['Last Name']) : ''); $nospaces = str_replace(' ', '', $_POST['Last Name']); if($_POST['Last Name'] != '' && ctype_alpha) { $cleans['Last Name'] = $_POST['Last Name']; } else { $errors_M[] = 'Last Name is required.'; } //making sure @ is inserted $_POST['Email address'] = (isset($_POST['Email address']) ? trim($_POST['Email address']) : ''); $email = explode('@', $_POST['Email address']); $add_email = count($email); if ($add_email == 2) { $email_domain = $email[1]; if (strpos($email_domain, '.') !== false) { $cleans['Email address'] = $_POST['Email address']; } else { $errors_M[] = 'Your email is not correct please try again.'; } } else { $errors_M[] = 'Incorrect email.'; } $_POST['Username'] = (isset($_POST['Username']) ? trim($_POST['Username']) : ''); if($_POST['Username'] != '' && ctype_alnum) { $cleans['Username'] = $_POST['Username']; } else { $errors_M[] = 'Please supply username with alphnumeric character.'; } //correctly formatted $_POST['password'] = (isset($_POST['password']) ? trim($_POST['password']) : ''); // allows the alphnumeric characters if($_POST['password'] != ' ' && ctype_alnum( $_POST['password'])) { $cleans['password'] = $_POST['password']; } else { $errors_M[] = 'Please use alphnumiric characters.'; } } $output = ''; // counts errors if (isset($_POST['submit']) && count($errors_M)==0) { if ($_POST['submit'] == 'Logout') { // Time line set $output .= ""; unset($_SESSION['Username']); $_SESSION = array(); setcookie('Username','',time()-42000); $_COOKIE = array(); session_destroy(); header("Location: logout.php"); } else { // writes into file and closes $handle = fopen('..user.txt','a'); if(!$handle){ echo " Please try later"; die(); } fwrite($handle, $info); fwrite($handle, "\n"); fclose($handle); setcookie('Username',$cleans['Username']); $_SESSION['Username'] = $cleans['Username'];?><?php
echo "Thank you for registering with us. Now please log in.";?>
<meta http-equiv="Refresh" content="5;URL=logon.php"></h5>
<?php
}
echo "Thank you for registering with us. Now please log in.";?>
<meta http-equiv="Refresh" content="5;URL=logon.php"></h5>
<?php
}
}
else
{
// counts errors and produces some security
if (count($errors_M)>0)
{
$output .= ‘
- ’;
- ’.htmlentities($data).’ ’;
foreach ($errors_M as $data)
{
$output .= ‘
}
$output .= ‘
}
$output .= '<form action="'.htmlentities($_SERVER['PHP_SELF']).'" method="post">
<fieldset>';
if(!isset($_SESSION[‘Username’]))
{
?>
Welcome
Page 1 Page 2 Page 3 <?php //form included in the php page $output .= ' First Name:Last Name:
Email address:
Username:<br Password: '; } if (isset($_SESSION['Username'])) { $output .= ''; } $output .= ' '; } echo $output; ?>