If this is your first visit, be sure to
check out the FAQ by clicking the
link above. You may have to register
before you can post: click the register link above to proceed. To start viewing messages,
select the forum that you want to visit from the selection below.

Enjoy an ad free experience by logging in. Not a member yet? Register.

ISSET for Arrays?

To give myself tighter control over error messages during form handling I thought it might be best if I were to create an array and use array_push() every time my conditionals found an array and then later use a loop to echo an unordered list of errors.

The issue that I am finding is that my conditional echos an unordered list anyway, which must mean that my conditional (whether any error messages were sent to the arrays) are coming up positive when I don't want them to. I have tried both count() and isset() on the php_errors and / or php_success arrays. Here is my code (count() conditionals about 2/3 the way down):

if(strlen($trimmed['first_name']) <=30 && preg_match('/^[A-Z \'.-]{2,30}$/i', $trimmed['first_name'])){
$fn = mysqli_real_escape_string($dbc, $trimmed['first_name']);
$first_name_query = "UPDATE users SET first_name = '$fn'";
$first_name_results = mysqli_query($dbc, $first_name_query) or trigger_error("Query $first_name_query\n<br />MySQL Error:"
. mysqli_error($dbc));
if (mysqli_affected_rows($dbc) == 1) {array_push($php_sucess, 'Your first name has been updated');}
else {array_push($php_errors, 'Sorry but your first name was unable to be updated.');}
}
else { //if first name was greater than 30 characters long
array_push($php_errors, 'Please enter a first name that is 30 characters long or less.');
}

if (strlen($trimmed['last_name']) <=30 && preg_match ('/^[A-Z \'.-]{2,30}$/i', $trimmed['last_name'])){
$ln = mysqli_real_escape_string($dbc, $trimmed['last_name']);
$last_name_query = "UPDATE users SET last_name ='$ln'";
$last_name_results = mysqli_query($dbc, $last_name_query) or trigger_error("Query $last_name_query\n<br />MySQL Error:"
. mysqli_error($dbc));
if (mysqli_affected_rows($dbc) == 1){array_push($php_success, 'Your last name has been updated.');}
else {array_push($php_errors, 'Sorry but your last name was unable to be updated.');}
}
else {// if last name is not under 30 characters
array_push($php_errors, 'Please enter a last name that is 30 characters long or less.');
}