RORJACK Posted May 4, 2012 Share Posted May 4, 2012 Hi guys, running through this tutorial at the moment: http://www.tizag.com/phpT/forms.php I seem to keep having problems with the $_POST variable. Is that obsolete syntax now? Here's the part I get an error on: <html> <body> <?php $quantity=$_POST['quantity']; $item=$_POST['item']; echo "You ordered".$quantity."".$item.".<br/>."; echo "Thank you for ordering from Boombaby art supppplies!"; ?> </body> </html> Here's the error: ( ! ) Notice: Undefined index: quantity in C:\wamp\www\process.php on line 4 Call Stack # Time Memory Function Location 1 0.0009 363936 {main}( ) ..\process.php:0 ( ! ) Notice: Undefined index: item in C:\wamp\www\process.php on line 5 Call Stack # Time Memory Function Location 1 0.0009 363936 {main}( ) ..\process.php:0 You ordered. .Thank you for ordering from Boombaby art supppplies! Any help would be appreciated. I tried googling but everything didn't seem to answer my question or was too confusing. Thanks. Quote Link to comment https://forums.phpfreaks.com/topic/262047-_post-help/ Share on other sites More sharing options...
Drummin Posted May 4, 2012 Share Posted May 4, 2012 Well, you probably won't have that message after POST. You would usually add a name to your submit input like name="submit" then for the "processing check if the value isset(). <?php if (isset($_POST['submit]')){ $quantity=$_POST['quantity']; $item=$_POST['item']; echo "You ordered".$quantity."".$item.".<br/>."; echo "Thank you for ordering from Boombaby art supppplies!"; } ?> Quote Link to comment https://forums.phpfreaks.com/topic/262047-_post-help/#findComment-1342898 Share on other sites More sharing options...
downah Posted May 4, 2012 Share Posted May 4, 2012 echo "You ordered".$quantity."".$item.".<br/>."; echo "Thank you for ordering from Boombaby art supppplies!"; to echo "You ordered" . $quantity . $item .".<br/>"; echo "Thank you for ordering from Boombaby art supppplies!"; ? That is what I would try, not sure if it helps Quote Link to comment https://forums.phpfreaks.com/topic/262047-_post-help/#findComment-1342944 Share on other sites More sharing options...
scootstah Posted May 4, 2012 Share Posted May 4, 2012 The $_POST variable is only populated after you send a POST request (like submit a form). So, you first need to determine if a POST request was even sent before you need worry about anything to do with the $_POST variable. If you try to use the $_POST variable without a POST request, you will just get index undefined errors as you did here. So either Drummin suggested or, an easier way that I like (since it doesn't require any specific fields) is this: if (!empty($_POST)) { // do whatever here } Quote Link to comment https://forums.phpfreaks.com/topic/262047-_post-help/#findComment-1342951 Share on other sites More sharing options...
RORJACK Posted May 4, 2012 Author Share Posted May 4, 2012 Hi guys, I figured it out thanks. Quote Link to comment https://forums.phpfreaks.com/topic/262047-_post-help/#findComment-1343092 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.