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
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
Share on other sites

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

Link to comment
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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.