Jump to content

Error Displaying Help :'(


HoTDaWg

Recommended Posts

hello,

 

i am making a registration form for my website, and basically it is the error checker isnt working for mE:S it is honestly because i suck at arrays, and, forgive me for saying this, but i dont seem to be getting any help from the manual  ??? i donno why the manual is confusing me. the problem is it displays the form but once the user hits submit it shows nothing. No errors and it doesnt even say, "done".

 

<?php
function form(){
$submit = $_GET['submit']; 
if(!isset($submit)){
   	echo '<form name="hey" action="'.$_SERVER[php_SELF].'"><input type="text" maxlength="12" name="username" value=""><br><input type="text" name="password" value="" maxlength="50"><br><input type="text" maxlength="80" name="email" value=""><br><input type="submit" name="submit" value="submit"></form>';
   	}
}
//It Begins.
$arrErrors = array();
$conn = mysql_pconnect("localhost","******","**************");
   		mysql_select_db("**********");
//Get it, get it now.
if(isset($_POST['submit'])){
$username = $_GET['username'];
$password = $_GET['password'];
$email = $_GET['email'];
$submit = $_GET['submit']; 
$ip = GetHostByName($REMOTE_ADDR);
$date = date('d m Y @ h:i:s A'); 
//Empty?! I THINK NOT!
	if(empty($username)){
	$arrErrors['error'] = array('type'=>'empty', 'description'=>"The Username Field has invalid characters.");
	}
	if(empty($password)){
	$arrErrors['error'] = array('type'=>'empty', 'description'=>"The Pasword Field has invalid characters.");
	}
	if(empty($email)){
	$arrErrors['error'] = array('type'=>'empty', 'description'=>"The E-Mail Field has invalid characters.");
	}
//Too Long?! I THINK NOT!
	if(strlen($username) > 12){
	$arrErrors['error'] = array('type'=>'toolong', 'description'=>"The Username Field exeeds the limit of <b>12</b> characters");
	}
	if(strlen($password) > 14){
	$arrErrors['error'] = array('type'=>'toolong', 'description'=>"The Password Field exeeds the limit of <b>14</b> characters");
	}		
	if(strlen($email) > 50){
	$arrErrors['error'] = array('type'=>'toolong', 'description'=>"The Email Field exeeds the limit of <b>50</b> characters");		
	}
//Invalid characters...grr...
        if (preg_match('|[^a-z\d]|i', $username)) {
	$arrErrors['error'] = array('type'=>'invalidchars', 'description'=>"The Username Field has invalid characters.");
        }
	if (preg_match('|[^a-z\d]|i', $password)) {
	$arrErrors['error'] = array('type'=>'invalidchars', 'description'=>"The Password Field has invalid characters.");
	}
//FINALLY!
	if(!count($arrErrors) > 0){
	//Secure the variables
   		$email=strip_tags($email);
   		$username=strip_tags($username);
   		$password=strip_tags($password);
   		$email=addslashes($email);
   		$username=addslashes($username);
   		$password=addslashes($password);
//Create the display name
   		$displayname =&$username;
   		$username=strtolower($username);
//final filter
   		$username = mysql_real_escape_string($username);
   		$password = mysql_real_escape_string($password);
   		$displayname = mysql_real_escape_string($displayname);
   		$email = mysql_real_escape_string($email);
   		$password = md5($password);
	echo "done";
	}else{
	$strError = '<div border="0"><p>Please check the following and try again:</p><ul>';
// Get each error and add it to the error string
        // as a list item.
        	foreach ($arrErrors as $key=>$value){
            	$strError .= "<li>{$arrErrors['error']}</li>";
        	}
        	$strError .= '</ul></div>';
		echo $strError;
	}
}else{
echo form();
}
?>

Link to comment
Share on other sites

like, i am introducing the error message like this:

<?php
$arrErrors['error'] = array('type'=>'invalidchars', 'description'=>"The Password Field has invalid characters.");
?>

 

and im asking PHP to display the errors like this:

<?php
        	foreach ($arrErrors as $key=>$value){
            	$strError .= "<li>{$arrErrors['error']}</li>";
        	}
        	$strError .= '</ul></div>';
		echo $strError;
	}
?>

 

what is the correct way to do this?

Link to comment
Share on other sites

Well for one, why are you doing this:

 

	if(!count($arrErrors) > 0){

 

??? If not count arrerrors is greater than 0?

 

Why not just say if count($arrErrors) > 0  ?? Why have the not? (That is part of the problem)

 

As for printing arrays do this.

 

print "<pre>";
print_r($arrErrors);
print "</pre>";

 

 

--FrosT

 

Link to comment
Share on other sites

chagned the code but still its showing a blank page ???

<?php
function form(){
$submit = $_GET['submit']; 
if(!isset($submit)){
   	echo '<form name="hey" action="'.$_SERVER[php_SELF].'"><input type="text" maxlength="12" name="username" value=""><br><input type="text" name="password" value="" maxlength="50"><br><input type="text" maxlength="80" name="email" value=""><br><input type="submit" name="submit" value="submit"></form>';
   	}
}
//It Begins.
$arrErrors = array();
$conn = mysql_pconnect("localhost","****","*******");
   		mysql_select_db("*********");
//Get it, get it now.
if(isset($_POST['submit'])){
$username = $_GET['username'];
$password = $_GET['password'];
$email = $_GET['email'];
$submit = $_GET['submit']; 
$ip = GetHostByName($REMOTE_ADDR);
$date = date('d m Y @ h:i:s A'); 
//Empty?! I THINK NOT!
	if(empty($username)){
	$arrErrors['error'] = array('type'=>'empty', 'description'=>"The Username Field has invalid characters.");
	}
	if(empty($password)){
	$arrErrors['error'] = array('type'=>'empty', 'description'=>"The Pasword Field has invalid characters.");
	}
	if(empty($email)){
	$arrErrors['error'] = array('type'=>'empty', 'description'=>"The E-Mail Field has invalid characters.");
	}
//Too Long?! I THINK NOT!
	if(strlen($username) > 12){
	$arrErrors['error'] = array('type'=>'toolong', 'description'=>"The Username Field exeeds the limit of <b>12</b> characters");
	}
	if(strlen($password) > 14){
	$arrErrors['error'] = array('type'=>'toolong', 'description'=>"The Password Field exeeds the limit of <b>14</b> characters");
	}		
	if(strlen($email) > 50){
	$arrErrors['error'] = array('type'=>'toolong', 'description'=>"The Email Field exeeds the limit of <b>50</b> characters");		
	}
//Invalid characters...grr...
        if (preg_match('|[^a-z\d]|i', $username)) {
	$arrErrors['error'] = array('type'=>'invalidchars', 'description'=>"The Username Field has invalid characters.");
        }
	if (preg_match('|[^a-z\d]|i', $password)) {
	$arrErrors['error'] = array('type'=>'invalidchars', 'description'=>"The Password Field has invalid characters.");
	}
//FINALLY!
	if(count($arrErrors) < 0){
	//Secure the variables
   		$email=strip_tags($email);
   		$username=strip_tags($username);
   		$password=strip_tags($password);
   		$email=addslashes($email);
   		$username=addslashes($username);
   		$password=addslashes($password);
//Create the display name
   		$displayname =&$username;
   		$username=strtolower($username);
//final filter
   		$username = mysql_real_escape_string($username);
   		$password = mysql_real_escape_string($password);
   		$displayname = mysql_real_escape_string($displayname);
   		$email = mysql_real_escape_string($email);
   		$password = md5($password);
	echo "done";
	}else{
	$strError = '<div border="0"><p>Please check the following and try again:</p><ul>';
// Get each error and add it to the error string
        // as a list item.
        	foreach ($arrErrors as $key=>$value){
            	print "<pre>";
			print_r($arrErrors);
			print "</pre>";
        	}
        	$strError .= '</ul></div>';
		echo $strError;
	}
}else{
echo form();
}
?>

Link to comment
Share on other sites

Why is username and password being set by the get and not the post?

 

In the form tag you should add <form method="POST">

 

and probably before the empty do if isset or do that check in the variable declaration. Because if the $_POST['username'] is not set, that's an error. But by setting it equal to something may throw it off.

 

If that does not work I start by printing out information at certain points of the script until I find where no output is being received, that is where my problem lies.

 

--FrosT

 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

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.