Hi,
im posting cause im trying to find the error in the following code but i just can't see it
function CHECK_EMPTY($_POST){
if(!isset($_POST['First_Name']) && !isset($_POST['Last_Name'])){
$ErrorMsG[] = "Please Enter a Correct Name in the NAME Fields!";
}
if((!isset($_POST['Address1']) || !isset($_POST['Address2'])) && !isset($_POST['City'])){
$ErrorMsG[] = "Please Enter An Address";
}
if(!isset($_POST['Email'])){
$ErrorMsG[] = "Please Enter an Email Address in the EMAIL ADDRESS Field!";
}else{
$ErrorMsG[] = CHECK_EMAIL($_POST['Email']);
}
if(is_array($ErrorMsG)){
while(list($key,$val)=each($ErrorMsG)){
echo $key.",".$val;
}
return $ErrorMsG;
}
}
The above code validates some posted data from a form. The thing is i left some of the form data to test the validation which i get but while it lists the key it doesnt list the value and it isnt looping as i only get one key output.
can any one see wheres the error?
VAlidate $_POST variables
Moderator: General Moderators
- twigletmac
- Her Royal Site Adminness
- Posts: 5371
- Joined: Tue Apr 23, 2002 2:21 am
- Location: Essex, UK
Try this, it works as expected for me:
Mac
Code: Select all
<?php
function CHECK_EMPTY(){
$ErrorMsG = array();
if (empty($_POST['First_Name']) || empty($_POST['Last_Name'])) {
$ErrorMsG[] = 'Please Enter a Correct Name in the NAME Fields!';
}
if ((empty($_POST['Address1']) || empty($_POST['Address2'])) && empty($_POST['City'])) {
$ErrorMsG[] = 'Please Enter An Address';
}
if (!isset($_POST['Email'])) {
$ErrorMsG[] = 'Please Enter an Email Address in the EMAIL ADDRESS Field!';
} else {
$ErrorMsG[] = CHECK_EMAIL($_POST['Email']);
}
echo '<pre>';
print_r($ErrorMsG);
echo '</pre>';
return $ErrorMsG;
}
?>- kendall
- Forum Regular
- Posts: 852
- Joined: Tue Jul 30, 2002 10:21 am
- Location: Trinidad, West Indies
- Contact:
VAlidate $_POST variables
hey,
thanks for the tips. question??
i saw that you $ErrorMsG = array();
Did i need to define $Error Msg as an array??
I thought $ErrorMsG[] automatically defines that?
thanks for the tips. question??
i saw that you $ErrorMsG = array();
Did i need to define $Error Msg as an array??
I thought $ErrorMsG[] automatically defines that?
- twigletmac
- Her Royal Site Adminness
- Posts: 5371
- Joined: Tue Apr 23, 2002 2:21 am
- Location: Essex, UK