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"; } } Link to comment https://forums.phpfreaks.com/topic/159537-solved-can-a-post-variable-be-used-in-in_array-query/ 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'])) { Link to comment https://forums.phpfreaks.com/topic/159537-solved-can-a-post-variable-be-used-in-in_array-query/#findComment-841552 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.