Noobie John here. I now can't get my PHP script to display $_POST variables. I've researched this and as far as I can tell my code is correct. Here is the code:
HTML
[color="#0000FF"] <html> <body> <h1> Calculation Form </h1> <form action="calculation.php" method="POST"> <p> <b> Enter 1st number: </b> <input type="text" name="a"> <b>Enter 2nd number: </b> <input type="text" name="b"> </p> <p> <input type="submit" name="calculate" value="Add"> <input type="submit" name="calculate" value="Subtract"> <input type="submit" name="calculate" value="Multiply"> <input type="submit" name="calculate" value="Divide"> </p> </form> </body> </html> [/color]
PHP script
[color="#0000FF"]<?php
switch ($_POST[calculate])
{
case "Add":
echo $_POST[a]." + ".$_POST[b]." = ".($_POST[a]+$_POST[b]);
break;
case 'Subtract':
echo $_POST[a]." - ".$_POST[b]." = ".($_POST[a]-$_POST[b]);
break;
case 'Multiply':
$t=$_POST[a]*$_POST[b];
echo $_POST[a]." x ".$_POST[b]." = ".($_POST[a]*$_POST[b]);
break;
case 'Divide':
$t=$_POST[a]/$_POST[b];
echo $_POST[a]." divided by ".$_POST[b]." = ".($_POST[a]/$_POST[b]);
break;
}
?></color>
Here is a sample ouput when I click the "Add" button"
+ = 0
The buttons and the switch in my PHP work. If I click Multiply I get:
x = 0
Any ideas as to why this is happening.
This post has been edited by CTphpnwb: 29 April 2010 - 12:38 PM
Reason for edit:: Code tags use [ ], not <>, even though the icon is <> !

New Topic/Question
Reply




MultiQuote








|