Jump to content
xisto Community
Sign in to follow this  
iGuest

Php Register Form Validation Help

Recommended Posts

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

 

 

 

 

 

 

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "[url="https://w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"]http://www.w3.org/TRtml1-strict.dtd;<html xmlns="[url="https://w3.org/1999/xhtml"]http://www.w3.org/1999/xhtml/; xml:lang="en" lang="en"><head><title>Sign Up to our Mailing List!</title><meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /></head><body><?php//arrays$output = '';$cleans = array();//checks submitif (isset($_POST['submit']) && $_POST['submit'] != 'Logout'){     if (isset ($_POST['First Name'])) {     ($_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'];	}   $output .= '<p>First Name: '.htmlentities [$clean['First Name']).'</p>';  else	{		$output .= 'First Name is required with alphanumeric characters.';	}} else {$output .= '<p>First Name: Not submitted</p>';	 // alphabet characters only   if (isset ($_POST['Last Name'])){     $_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'];    $output .= '<p>Last Name: '.htmlentities [$clean['Last Name']).'</p>';}	else	{		$output .= 'Last Name is required.';	}//making sure @ is inserted  	if (isset ($_POST['Email address'])) {$_POST['Email address'] = trim($_POST['Email address']) : '');			  	$email_parts  = explode([email=""]'@'[/email], $_POST['Email address']);  	$num_email_parts = count ($email_parts);  	if ($num_email_parts == 2) {	{		$email_domain = $email_parts[1];		if (strpos($email_domain, '.') !== false) {		{			$cleans['Email address'] = $_POST['Email address'];   $output .= '<p>Email address: '.htmlentities($clean['Email address']).'</p>';		}		else		{			$output .= '<p>Your email is not correct please try again.'</p>;		}	}	else	{		$output .= 'Incorrect email.';	}		$_POST['Username'] = (isset($_POST['Username']) ? trim($_POST['Username']) : '');  if($_POST['Username'] != '' && ctype_alnum)  	{		$cleans['Username'] = $_POST['Username'];	}	else	{		$output .= '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	{		$output .= <p>'Please use alphnumiric characters.'</p>;	}}$output = '';// counts errors{	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'];?><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	{	  		{			$output .= '<li>'.htmlentities($data).'</li>';		}		$output .= '</ul>';	}  		$output .= '<form action="'.htmlentities($_SERVER['PHP_SELF']).'" method="post">					<fieldset>';   if(!isset($_SESSION['Username']))   {?><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/1999/xhtml/; xml:lang="en" lang="en"><head><title>Registered Page</title><meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /></head><body><!--Navigation starts here....--><h1>Welcome</h1><a href="page1.php"> Page 1</a>  <a href="page2.php">Page 2</a>  <a href="page3.php">Page 3</a><?php	//form included in the php page  	        $output .= '	  <form>;	First Name: <input type="text" name="First Name"/><br/>   Last Name: <input type="text" name="Last Name" /><br />	 <label for="ea">Email address:</label><input type="text" name="Email address"/><br>   Username:<input type="text" name="Username"/><br   <label for="password">Password:</label><input type="password"name="password"id="password"size="20" />	    		<input type="submit" name="submit" value="Register" />';	}	 if (isset($_SESSION['Username']))	  {	  		$output .= '<input type="submit" name="submit" value="Logout" />';	   }	$output .= '</fieldset>	 </form>';}echo $output;?></body></html>
Edited by moderator (see edit history)

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

×
×
  • Create New...

Important Information

Terms of Use | Privacy Policy | Guidelines | We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.