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";
   }
}

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.