Jump to content

Recommended Posts

I have just re-installed php (version 5.2.0-dev), and it's not working right. I think I have installed it properly, phpinfo() is working, but variables from a html form ($_POST['variablename'], for example) aren't passed on to PHP, it just doesn't reveive anything.. Before the re-install everything worked fine (...).

I am pretty clueless as to what might be causing this. Any help or thoughts would be appreciated.
Link to comment
https://forums.phpfreaks.com/topic/15336-problem-with-_post-variables/
Share on other sites

I figured it wasn't working by trying to run the following example.

orderform.html:
[code]
<html>
<body>
<form action="processorder.php" method="post">
<table border="0">
<tr bgcolor="#cccccc">
  <td width="150">Item</td>
  <td width="15">Quantity</td>
</tr>
<tr>
  <td>Tires</td>
  <td align="center"><input type="text" name="tireqty" size="3"
    maxlength="3"></td>
</tr>
<tr>
  <td>Oil</td>
  <td align="center"><input type="text" name="oilqty" size="3" maxlength="3"></td>
</tr>
<tr>
  <td>Spark Plugs</td>
  <td align="center"><input type="text" name="sparkqty" size="3"
    maxlength="3"></td>
</tr>
<tr>
  <td>How did you find us?</td>
  <td><select name="find">
        <option value = "a">I'm a regular customer</option>
        <option value = "b">TV advertising</option>
        <option value = "c">Phone directory</option>
        <option value = "d">Word of mouth</option>
      </select>
  </td>
</tr>
<tr>
  <td colspan="2" align="center"><input type="submit" value="Submit Order"></td>
</tr>
</table>
</form>
</body>
</html>
[/code]

processorder.php:
[code]
<?php
  $tireqty = $_POST['tireqty'];
  $oilqty = $_POST['oilqty'];
  $sparkqty = $_POST['sparkqty'];
  $find = $_POST['find'];
?>
<html>
<head>
  <title>Order Results</title>
</head>
<body>
<?php
echo '<p>Order processed at ';
echo date('H:i, jS F');
echo '</p>';

echo '<p>Your order is as follows: </p>';

$totalqty = 0;
$totalqty = $tireqty + $oilqty + $sparkqty;
echo 'Items ordered: '.$totalqty.'<br />';

if( $totalqty == 0)
{
  echo 'You did not order anything on the previous page!<br />';
}
else
{
  if ( $tireqty>0 )
    echo $tireqty.' tires<br />';
  if ( $oilqty>0 )
    echo $oilqty.' bottles of oil<br />';
  if ( $sparkqty>0 )
    echo $sparkqty.' spark plugs<br />';
}

$totalamount = 0.00;

define('TIREPRICE', 100);
define('OILPRICE', 10);
define('SPARKPRICE', 4);

$totalamount = $tireqty * TIREPRICE
            + $oilqty * OILPRICE
            + $sparkqty * SPARKPRICE;

echo 'Subtotal: $'.number_format($totalamount,2).'<br />';

$taxrate = 0.10;
$totalamount = $totalamount * (1 + $taxrate);
echo 'Total including tax: $'.number_format($totalamount,2).'<br />';


if($find == 'a')
  echo '<p>Regular customer.</p>';
elseif($find == 'b')
  echo '<p>Customer referred by TV advert.</p>';
elseif($find == 'c')
  echo '<p>Customer referred by phone directory.</p>';
elseif($find == 'd')
  echo '<p>Customer referred by word of mouth.</p>';
else
  echo '<p>We do not know how this customer found us.</p>';
?>
</body>
</html>
[/code]

Sorry for the long code, I picked this example because I know it was working before the re-install. No matter what I put in the orderform, I always get the same output:

"Order processed at 18:55, 22nd July

Your order is as follows:
Items ordered: 0
You did not order anything on the previous page!
Subtotal: $0.00
Total including tax: $0.00

We do not know how this customer found us."

That's why I thought the variables aren't passed on the PHP. I'm running Apache on Windows XP, by the way.
You don't need a name in your form. Since the script that is being invoked by the form is not the same as the one that displays the form, you don't really to check if the submit button has been pressed. Upper or lowercase "post" in the method is fine.

At the top of your script put it this line:
[code]<?php echo '<pre>' . print_r($_POST,true) . '</pre>'; ?>[/code]
and see what is printed.

You can also try this test script:
[code]<?php
if (isset($_POST['submit']))phpinfo();
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<title>test forms</title>
</head>
<body>
<form method="post">
<input type="hidden" name="test" value="testing post">
<input type="submit" name="submit" value="Send">
</form>
</body>
</html>[/code]
Which should display the phpinfo() information when you press the "Send" button. Look in there for what's in the "$_POST" array.

Ken
Thanks Ken.

[code]
<?php echo '<pre>' . print_r($_POST,true) . '</pre>'; ?>
[/code]
prints out:

Array
(
)

Above the other output, which stays the same.

I also tried the test script, but that doesn't work either. When I press the "Send" button, the page 'refreshes' and nothing happens...
I already supposed there was nothing wrong with the code.. But I can't figure out what is causing the malfunction. I am on winxp and used these steps to install php: http://iamcode.net:64/projects/apache/php-win.awk - maybe something went wrong in that process?

I really hope someone might have some suggestions still, because I'm stuck right now.
Without actually seeing the set-up on your machine in person, it's pretty hard to diagnose what when wrong with your installation remotely. You may want to try to install everything again and make note of any errors that might show. You also may want to consider installing a package like xampp http://www.apachefriends.org/en/xampp-windows.html

Ken
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.