Arnsenal Posted November 6, 2011 Share Posted November 6, 2011 Can anyone tell me whats wrong, I think it has to do with my expression: if (!isset($value) || $value = '' || $value = NULL) { echo "<p class=\"unfilled-inputs\">$key</p>"; } Here is my code: $first_name = $_POST['first_name']; $last_name = $_POST['last_name']; $company = $_POST['company']; $phone_number = $_POST['phone']; $user_name = $_POST['user_name']; $password = $_POST['password']; $re_password = $_POST['re-password']; $email = $_POST['email']; $ip = $_POST['ip']; $ip_range = $_POST['ip_range']; $req_post_array = array( 'first name' => $first_name, 'last name' => $last_name, 'user name' => $user_name, 'password' => $password, 're password' => $re_password, 'email' => $email, 'ip' => $ip); print_r ($req_post_array); //to see what the array actually contains echo "The following fields needs to be filled out:<br />"; function check_if_set($value, $key){ if (!isset($value) || $value = '' || $value = NULL){ echo "<p class=\"unfilled-inputs\">$key</p>"; } } array_walk ($req_post_array, 'check_if_set'); It outputs: Array ( [first name] => Jim [last name] => Beam [user name] => Jimmy [password] => Beam [re password] => => [email protected] [ip] => 192.168.0.1 ) The following fields needs to be filled out: As we can see the function passed to the array_walk is not echoing what is should even though $req_post_array[re password] = ''; -- the if statement should be TRUE no? I noticed that if I change !isset to isset that it will echo every key in the array no matter if the values in the form are submitted or not. This is my HTML form if that matters.... <form id="create-account-form" action="../php/CreateUser.php" method="POST"> <fieldset> <legend><em>Personal Information:</em></legend> *First Name: <input name="first_name"type="text" maxlength="40" /><br /> *Last Name: <input name="last_name" type="text" maxlength="40" /><br /> Company: <input name="company" type="text" maxlength="40" /><br /> Phone #: <input name="phone" type="text" maxlength="14" /><br /> </fieldset><br /> <fieldset> <legend><em>Vuln-Vult Account Information:</em></legend> *User Name: <input name="user_name"type="text" maxlength="40" /><br /> *Password: <input name="password"type="text" maxlength="40" /><br /> *Re-enter Password: <input name="re-password" type="text" maxlength="40" /><br /> *Email: <input name="email" type="email" maxlength="40" /><br /> </fieldset><br /> <fieldset> <legend><em>Scan Settings:</em></legend> *I.P. Address (XXX.XXX.XXX.XXX)<input name="ip" type="text" maxlength="15" /><br /> I.P. Address Range (XXX.XXX.XXX.XXX-XXX.XXX.XXX.XXX)<input name="ip_range" type="text" maxlength="31" /> </fieldset><br /> <input type="submit" value="Submit" /> </form> Link to comment https://forums.phpfreaks.com/topic/250579-help-with-array_walk/ Share on other sites More sharing options...
Pikachu2000 Posted November 6, 2011 Share Posted November 6, 2011 Wrong operator. You're using an assignment = operator in the conditional. It should be a comparison == operator. if( !isset($value) || $value == '' || $value = NULL ) { Link to comment https://forums.phpfreaks.com/topic/250579-help-with-array_walk/#findComment-1285714 Share on other sites More sharing options...
Arnsenal Posted November 6, 2011 Author Share Posted November 6, 2011 whoops, noob mistake, thank you sir. Link to comment https://forums.phpfreaks.com/topic/250579-help-with-array_walk/#findComment-1285717 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.