Jump to content


Photo

Problem with $_POST[''] variables


  • Please log in to reply
12 replies to this topic

#1 kenek

kenek
  • New Members
  • Pip
  • Newbie
  • 7 posts

Posted 22 July 2006 - 03:43 PM

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.

#2 kenrbnsn

kenrbnsn
  • Staff Alumni
  • Advanced Member
  • 8,235 posts
  • LocationHillsborough, NJ, USA

Posted 22 July 2006 - 03:47 PM

How do you know it isn't working correctly. Please post the test script you are using.

Ken

#3 kenek

kenek
  • New Members
  • Pip
  • Newbie
  • 7 posts

Posted 22 July 2006 - 05:03 PM

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

orderform.html:
<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>

processorder.php:
<?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>

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.

#4 redarrow

redarrow
  • Members
  • PipPipPip
  • Advanced Member
  • 7,308 posts
  • Locationlondon

Posted 22 July 2006 - 05:11 PM

name your form and use a if post statement ok.

try it's free lol............

if($_POST['submit'] ) {

code

}

And also in your form use a uper case letter POST
Wish i new all about php DAM i will have to learn
((EMAIL CODE THAT WORKS))
http://simpleforum.ath.cx/mail2.inc
((PAYPAL INTEGRATION THAT WORKS))
http://simpleforum.a...aypal1_info.inc

#5 kenrbnsn

kenrbnsn
  • Staff Alumni
  • Advanced Member
  • 8,235 posts
  • LocationHillsborough, NJ, USA

Posted 22 July 2006 - 05:52 PM

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:
<?php echo '<pre>' . print_r($_POST,true) . '</pre>'; ?>
and see what is printed.

You can also try this test script:
<?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>
Which should display the phpinfo() information when you press the "Send" button. Look in there for what's in the "$_POST" array.

Ken

#6 kenek

kenek
  • New Members
  • Pip
  • Newbie
  • 7 posts

Posted 22 July 2006 - 06:05 PM

Thanks Ken.

<?php echo '<pre>' . print_r($_POST,true) . '</pre>'; ?>
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...

#7 Ferenc

Ferenc
  • Members
  • PipPipPip
  • Advanced Member
  • 94 posts

Posted 22 July 2006 - 07:00 PM

Your code is fine, something is not right with your server if it isn't working for you.
Everything you want to know is here.

#8 kenek

kenek
  • New Members
  • Pip
  • Newbie
  • 7 posts

Posted 22 July 2006 - 07:26 PM

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:6...che/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.

#9 kenek

kenek
  • New Members
  • Pip
  • Newbie
  • 7 posts

Posted 23 July 2006 - 07:12 AM

Does nobody have any idea??

#10 kenrbnsn

kenrbnsn
  • Staff Alumni
  • Advanced Member
  • 8,235 posts
  • LocationHillsborough, NJ, USA

Posted 23 July 2006 - 02:11 PM

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.apachefri...pp-windows.html

Ken

#11 kenek

kenek
  • New Members
  • Pip
  • Newbie
  • 7 posts

Posted 23 July 2006 - 03:17 PM

Ok, thanks anyway. Would it be of any use if I post this on the PHP Freaks Apache forum, or are the posters there the same as here?

Otherwise I'll just try to install everything again. I want to install it manually, I did it before, and it worked fine..

#12 wildteen88

wildteen88
  • Staff Alumni
  • Advanced Member
  • 10,482 posts
  • LocationUK, Bournemouth

Posted 23 July 2006 - 03:20 PM

Any reason why you are using a dev version? Why not downgrade to the PHP5.1.x?

I have no idea why this is.

#13 kenek

kenek
  • New Members
  • Pip
  • Newbie
  • 7 posts

Posted 23 July 2006 - 04:32 PM

Yes, I am planning to downgrade. I was using the dev version because I upgraded Apache to 2.2, and my php version couldn't handle that (see the link I posted earlier for details).




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users