Here is my php code:
<?php
$amount = $_GET["startingAmount"];
$whichWay = $_GET["whichWay"];
$conversion = $_GET["conversion"];
$step = $_GET["step"];
if (is_numeric($conversion))
{
if ($whichWay === "1")
{
echo "<table>";
echo "<tr><th>USD</th><th>Canadian</th></tr>";
for ($i = 0; $i <= 10; $i++)
{
$outputValue = $amount * $conversion;
echo "<tr><td>$amount</td><td>$outputValue</td></tr>";
$amount = $amount+$step;
}
echo "</table>";
}
else
{
echo "<table>";
echo "<tr><th>Canadian</th><th>USD</th></tr>";
for ($i = 0; $i <= 10; $i++)
{
$outputValue = $amount * $conversion;
echo "<tr><td>$amount</td><td>$outputValue</td></tr>";
$amount = $amount+$step;
}
echo "</table>";
}
}
else
{
echo "<p>You did not input a numeric value for both the amount you wanted to convert and for the conversion rate.<br>Please go back and do it again</p>";
}
?>
Here is the html form that sends the information:
<body>
<h1>USD/Canadian Money Conversion Site</h1>
<div>
<form method="get" action="output.php">
Starting Amount:
<select name="startingAmount" size="1">
<option name="1">1</option>
<option name="10">10</option>
<option name="20">20</option>
</select><br>
Conversion type:
<select name="whichWay" size="1">
<option name="1">USD to Canadian</option>
<option name="2">Canadian to USD</option>
</select><br>
Conversion Rate: <input type="text" name="conversion" required><br>
Step:
<select name="step" size="1">
<option name="1">1</option>
<option name="2">2</option>
<option name="3">3</option>
<option name="4">4</option>
</select><br>
<input type="submit">
</form>
</div>
</body>
For some reason the php does not recognize the value of whichWay if the user selects USD to Canadian or vice versa and just runs the else statement. Everything else works fine. The program can run the else statement and the rest of the variables work fine. Any help would be greatly appreciated.
Aucun commentaire:
Enregistrer un commentaire