Jump to content

[SOLVED] Can a POST variable be used in "in_array" query?


DLR

Recommended Posts

I have saved an array as a SESSION variable to validate input. But the POST variable does not show as true when doing a "in_array" check.

I have read up, and tried all I can and am now stumped. Help please!

 

$a = array("Existing","New","Referral","Web site/email/call");
$_SESSION['list'] = $a;

echo '<form action = "test.php" method="post">';
echo "<select name='from'>";
foreach($a as $value) {
   echo "<option value=' " . $value . " ' >"  . $value . "</option>";
}
echo "</select>";
   
echo "<p><button type='submit'>Enter</button> ";

// hidden value "b" so that "if" only works after POST['from'] is  set
echo "<input type='hidden' name='b' value='20'>";  echo "<form>";

if($_POST['b'] == 20) {
   if(in_array($_POST['from'], $_SESSION['list'])) {
      echo "IN ARRAY!";
   } else {
      echo "NOT in array";
   }
}

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.