Guest Tim_Christopher Posted July 23, 2007 Share Posted July 23, 2007 Hi, I've got a basic web form something like: <form action=".." method="$_POST"> <input type="checkbox" name="userId[]" value="1" /> <input type="checkbox" name="userId[]" value="2" /> <input type="checkbox" name="userId[]" value="3" /> <input type="submit" name="submit" value="Click Here" /> </form> The following is what I would expect to happen assuming all 3 were checked: $_POST = array(3) { [0]=> string(1) "1" [1]=> string(1) "2" [2]=> string(1) "3" } $_REQUEST = array(3) { [0]=> string(1) "1" [1]=> string(1) "2" [2]=> string(1) "3" } The actual output is: $_POST = string(5) "Array" $_REQUEST = array(3) { [0]=> string(1) "1" [1]=> string(1) "2" [2]=> string(1) "3" } Can anyone explain this?.. The code used to work however I have since upgraded to PHP5 and there may have been alternations in the php.ini file. I know I could just go through changing every instance of $_POST to $_REQUEST but it just doesn't feel right, and I'd rather fix whatever has changed. Any help would be appreciated Quote Link to comment https://forums.phpfreaks.com/topic/61348-php5-problem-with-array-submitted-from-html-form/ Share on other sites More sharing options...
sasa Posted July 23, 2007 Share Posted July 23, 2007 change method="$_POST" to method="POST" variable $_POST is empty and the form use deaful method Quote Link to comment https://forums.phpfreaks.com/topic/61348-php5-problem-with-array-submitted-from-html-form/#findComment-305263 Share on other sites More sharing options...
Guest Tim_Christopher Posted July 23, 2007 Share Posted July 23, 2007 Yeah - that was just a typo on my post, but I can't find an edit button. It should actually read: <form action=".." method="POST"> <input type="checkbox" name="userId[]" value="1" /> <input type="checkbox" name="userId[]" value="2" /> <input type="checkbox" name="userId[]" value="3" /> <input type="submit" name="submit" value="Click Here" /> </form> Quote Link to comment https://forums.phpfreaks.com/topic/61348-php5-problem-with-array-submitted-from-html-form/#findComment-305273 Share on other sites More sharing options...
trq Posted July 23, 2007 Share Posted July 23, 2007 How exactly are you printing these results. Using... <form method="POST"> <input type="checkbox" name="userId[]" value="1" /> <input type="checkbox" name="userId[]" value="2" /> <input type="checkbox" name="userId[]" value="3" /> <input type="submit" name="submit" value="Click Here" /> </form> <?php if (isset($_POST['submit'])) { echo '<pre>'; print_r($_POST); echo '</pre>'; } ?> this code (and ticking all options), produces.... Array ( [userId] => Array ( [0] => 1 [1] => 2 [2] => 3 ) [submit] => Click Here ) for me. Quote Link to comment https://forums.phpfreaks.com/topic/61348-php5-problem-with-array-submitted-from-html-form/#findComment-305277 Share on other sites More sharing options...
Guest Tim_Christopher Posted July 24, 2007 Share Posted July 24, 2007 That code produces: Array ( [userId] => Array [submit] => Click Here ) for me. Quote Link to comment https://forums.phpfreaks.com/topic/61348-php5-problem-with-array-submitted-from-html-form/#findComment-306193 Share on other sites More sharing options...
Guest Tim_Christopher Posted July 24, 2007 Share Posted July 24, 2007 Or for a more complete example the following code: <form method="POST"> <input type="checkbox" name="userId[]" value="1" /> <input type="checkbox" name="userId[]" value="2" /> <input type="checkbox" name="userId[]" value="3" /> <input type="submit" name="submit" value="Click Here" /> </form> <?php if (isset($_POST['submit'])) { echo '<pre>'; print_r($_POST); echo '</pre>'; } if (isset($_POST['submit'])) { echo '<pre>'; print_r($_REQUEST); echo '</pre>'; } ?> Produces: Array ( [userId] => Array [submit] => Click Here ) Array ( [userId] => Array ( [0] => 1 [1] => 2 [2] => 3 ) [submit] => Click Here ) Quote Link to comment https://forums.phpfreaks.com/topic/61348-php5-problem-with-array-submitted-from-html-form/#findComment-306195 Share on other sites More sharing options...
Guest Tim_Christopher Posted July 26, 2007 Share Posted July 26, 2007 Any ideas anyone?! Quote Link to comment https://forums.phpfreaks.com/topic/61348-php5-problem-with-array-submitted-from-html-form/#findComment-307841 Share on other sites More sharing options...
redarrow Posted July 26, 2007 Share Posted July 26, 2007 try this please. <form method="POST" action="<?php echo $_SERVER['PHP_SELF']; ?>"> <input type="checkbox" name="userId[]" value="1" /> <input type="checkbox" name="userId[]" value="2" /> <input type="checkbox" name="userId[]" value="3" /> <input type="submit" name="submit" value="Click Here" /> </form> <?php if (isset($_POST['submit'])) { echo '<pre>'; print_r($_POST); echo '</pre>'; } ?> Quote Link to comment https://forums.phpfreaks.com/topic/61348-php5-problem-with-array-submitted-from-html-form/#findComment-307857 Share on other sites More sharing options...
Guest Tim_Christopher Posted July 26, 2007 Share Posted July 26, 2007 The output if any of the boxes are checked: Array ( [userId] => Array [submit] => Click Here ) Or if none are selected: Array ( [submit] => Click Here ) Quote Link to comment https://forums.phpfreaks.com/topic/61348-php5-problem-with-array-submitted-from-html-form/#findComment-307858 Share on other sites More sharing options...
Guest Tim_Christopher Posted August 7, 2007 Share Posted August 7, 2007 Does anyone have any ideas on this? Quote Link to comment https://forums.phpfreaks.com/topic/61348-php5-problem-with-array-submitted-from-html-form/#findComment-317491 Share on other sites More sharing options...
dbo Posted August 7, 2007 Share Posted August 7, 2007 Regardless of what's happening... what are you trying to accomplish? You just want to find out whats checked so you can process it? Quote Link to comment https://forums.phpfreaks.com/topic/61348-php5-problem-with-array-submitted-from-html-form/#findComment-317561 Share on other sites More sharing options...
drewbee Posted August 7, 2007 Share Posted August 7, 2007 That is very strange. What appears to be happening is that print_r is not iterating through the array, only staying at level 1. I use and script with PHP 5 and the data completely prints out for myself as well. try doing a var_dump($_POST) and see what comes out. Quote Link to comment https://forums.phpfreaks.com/topic/61348-php5-problem-with-array-submitted-from-html-form/#findComment-317599 Share on other sites More sharing options...
Guest Tim_Christopher Posted August 7, 2007 Share Posted August 7, 2007 The problem is not with print_r - it's with the $_POST array. In the $_REUQEST array: The variable $_REQUEST['userId'] is an array, .e.g. is_array(..) returns true. In the $_POST array: The variable $_POST['userId'] is a string containing the text 'Array'. Quote Link to comment https://forums.phpfreaks.com/topic/61348-php5-problem-with-array-submitted-from-html-form/#findComment-317635 Share on other sites More sharing options...
drewbee Posted August 7, 2007 Share Posted August 7, 2007 Well, I have no other ideas. There is nothing I am aware of that would cause this change going into PHP 5. Quote Link to comment https://forums.phpfreaks.com/topic/61348-php5-problem-with-array-submitted-from-html-form/#findComment-317706 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.