kenek Posted July 22, 2006 Share Posted July 22, 2006 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. Quote Link to comment https://forums.phpfreaks.com/topic/15336-problem-with-_post-variables/ Share on other sites More sharing options...
kenrbnsn Posted July 22, 2006 Share Posted July 22, 2006 How do you know it isn't working correctly. Please post the test script you are using.Ken Quote Link to comment https://forums.phpfreaks.com/topic/15336-problem-with-_post-variables/#findComment-62082 Share on other sites More sharing options...
kenek Posted July 22, 2006 Author Share Posted July 22, 2006 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><?phpecho '<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 JulyYour order is as follows:Items ordered: 0You did not order anything on the previous page!Subtotal: $0.00Total including tax: $0.00We 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. Quote Link to comment https://forums.phpfreaks.com/topic/15336-problem-with-_post-variables/#findComment-62100 Share on other sites More sharing options...
redarrow Posted July 22, 2006 Share Posted July 22, 2006 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 Quote Link to comment https://forums.phpfreaks.com/topic/15336-problem-with-_post-variables/#findComment-62102 Share on other sites More sharing options...
kenrbnsn Posted July 22, 2006 Share Posted July 22, 2006 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]<?phpif (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 Quote Link to comment https://forums.phpfreaks.com/topic/15336-problem-with-_post-variables/#findComment-62115 Share on other sites More sharing options...
kenek Posted July 22, 2006 Author Share Posted July 22, 2006 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... Quote Link to comment https://forums.phpfreaks.com/topic/15336-problem-with-_post-variables/#findComment-62121 Share on other sites More sharing options...
Ferenc Posted July 22, 2006 Share Posted July 22, 2006 Your code is fine, something is not right with your server if it isn't working for you. Quote Link to comment https://forums.phpfreaks.com/topic/15336-problem-with-_post-variables/#findComment-62150 Share on other sites More sharing options...
kenek Posted July 22, 2006 Author Share Posted July 22, 2006 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. Quote Link to comment https://forums.phpfreaks.com/topic/15336-problem-with-_post-variables/#findComment-62156 Share on other sites More sharing options...
kenek Posted July 23, 2006 Author Share Posted July 23, 2006 Does nobody have any idea?? Quote Link to comment https://forums.phpfreaks.com/topic/15336-problem-with-_post-variables/#findComment-62335 Share on other sites More sharing options...
kenrbnsn Posted July 23, 2006 Share Posted July 23, 2006 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.htmlKen Quote Link to comment https://forums.phpfreaks.com/topic/15336-problem-with-_post-variables/#findComment-62369 Share on other sites More sharing options...
kenek Posted July 23, 2006 Author Share Posted July 23, 2006 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.. Quote Link to comment https://forums.phpfreaks.com/topic/15336-problem-with-_post-variables/#findComment-62391 Share on other sites More sharing options...
wildteen88 Posted July 23, 2006 Share Posted July 23, 2006 Any reason why you are using a dev version? Why not downgrade to the PHP5.1.x?I have no idea why this is. Quote Link to comment https://forums.phpfreaks.com/topic/15336-problem-with-_post-variables/#findComment-62393 Share on other sites More sharing options...
kenek Posted July 23, 2006 Author Share Posted July 23, 2006 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). Quote Link to comment https://forums.phpfreaks.com/topic/15336-problem-with-_post-variables/#findComment-62426 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.