DLR Posted May 25, 2009 Share Posted May 25, 2009 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"; } } Quote Link to comment Share on other sites More sharing options...
vbnullchar Posted May 25, 2009 Share Posted May 25, 2009 try trimming... if(in_array(trim($_POST['from']), $_SESSION['list'])) { Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.