Jump to content

Help with array_walk


Arnsenal

Recommended Posts

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] => => JimBeam@gmail.com [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
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.