Jump to content


Photo

Array problem.....I think


  • Please log in to reply
No replies to this topic

#1 Nexx

Nexx
  • New Members
  • Pip
  • Newbie
  • 3 posts

Posted 20 July 2006 - 03:03 AM

Hi, I have a weird problem, and I think it has something to do with my array.

<?php
$arrError=array();
if (isset($_POST['hidden'])==1){
	if ($_POST['first_name']==''){
        $arrError['first_name'] = 'First Name: Everyone has a first name!';
			}else{$first_name=$_POST['first_name'];}
      
        //many other $_POST here, following the same format as the others.
	
	if ($_POST['email']==''){
        $arrError['email'] = 'Email: Email address must be in the name@domain.com format.';
			}else{$email=$_POST['email'];}
	
	if (count($arrError) == 0) {
		
		//database stuff here.
		
		}else{$strError = '<br /><div align=\"left\"><p class=\"error\">Please correct the following errors:</p>';
			foreach ($arrError as $strError) {
            	        $strError .= '<li>$strError</li>';
        		}
			$strError .= '</div>';	
			}
	
}	

echo $strError;
?>

When I hit the submit button, and a field fails to validate, it doesnt echo what I think should be in $strError. Instead it echos this:

  Email: Email address must be in the name@domain.com format.
•Email: Email address must be in the name@domain.com format.

• = bullet

Now if I enter an email address, it will do the same thing but with the previous failed field.

--------------------------------------------

Edit:

I figured it out,
<?php
foreach ($arrError as $error) {
   $strError .= '<li>$error</li>';
   }
   $strError .= '</div>';	
}?>

Ooops




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users