Jump to content

$_POST help


RORJACK

Recommended Posts

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.

Link to comment
https://forums.phpfreaks.com/topic/262047-_post-help/
Share on other sites

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!";
}
?>

Link to comment
https://forums.phpfreaks.com/topic/262047-_post-help/#findComment-1342898
Share on other sites

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
}

Link to comment
https://forums.phpfreaks.com/topic/262047-_post-help/#findComment-1342951
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.