TomTees Posted October 29, 2010 Share Posted October 29, 2010 How do I assign the entire $_POST array to a varible? This code isn't working... <?php echo 'FormHandler'; class FormHandler{ private $formValues = array(); $this->formValues = $_POST; } ?> TomTees Quote Link to comment https://forums.phpfreaks.com/topic/217231-how-do-you-assign-_post-to-an-array/ Share on other sites More sharing options...
rwwd Posted October 29, 2010 Share Posted October 29, 2010 Apart from making that public, there is nothing else wrong with that, though your basing this on the assumption that $_POST array is actually set, unless your invoking this after that check has been done... What do you get if you go like this:- print_r($this->formValues); check that first once the property has state... Rw Quote Link to comment https://forums.phpfreaks.com/topic/217231-how-do-you-assign-_post-to-an-array/#findComment-1128117 Share on other sites More sharing options...
TomTees Posted October 29, 2010 Author Share Posted October 29, 2010 Netbeans says this is a syntax error... $this->formValues = $_POST; And if I run my code (form) then I get this... ( ! ) Parse error: syntax error, unexpected T_VARIABLE, expecting T_FUNCTION in /Users/user1/Documents/DEV/++htdocs/Ecommerce/02_FormHandler.php on line 7 TomTees Quote Link to comment https://forums.phpfreaks.com/topic/217231-how-do-you-assign-_post-to-an-array/#findComment-1128120 Share on other sites More sharing options...
phpfreak Posted October 29, 2010 Share Posted October 29, 2010 You may want to do something like this: <?php foreach($_POST AS $key => $val) { $this->formValues[$key] = $val; } print_r($this->formValues); ?> See if that does the trick.. Quote Link to comment https://forums.phpfreaks.com/topic/217231-how-do-you-assign-_post-to-an-array/#findComment-1128133 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.