Code Help, Please!!

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
TheBrick33
Forum Newbie
Posts: 1
Joined: Thu Apr 19, 2007 3:48 pm

Code Help, Please!!

Post by TheBrick33 »

I am just starting PHP, and have decided to make a very simple multifunction calculator. It has a pull-down menu for selection of operations, but whenever I choose anything other than Addition it doesn't show anything on my php page

HTML:

<html>
<title>Math Operations</title>
<head></head>

<body>

<form method = "POST" action = "Math2.php">

<input type = "text" name = "A" length = "15">

<select name = "prop">
<option value = "Addition">Addition
<option value = "Subtraction">Subtraction
<option value = "Multiplication">Multiplication
<option value = "Division">Division
<option value = "Modulus">Modulus
</select>

<input type = "text" name = "B" length = "15">

<input type = "submit" value = "Equate">

</form>
</body>
</html>



PHP:

<?php

$A = $_POST['A'];
$B = $_POST['B'];

$prop = $_POST['prop'];

if ($prop == 'Addition'){
$C = $A + $B;
}

if ($prop == 'Subtraction'){
$D = $A - $B;
}

echo $D;
echo $C;

?>



Any suggestions on how to fix my problem would be a lot of help.
User avatar
guitarlvr
Forum Contributor
Posts: 245
Joined: Wed Mar 21, 2007 10:35 pm

Post by guitarlvr »

I put your code into an html file and a php file and it worked fine. Nothing works other than addition and subtraction because there are no conditionals for them but the adding and subtracting worked fine.

Wayne
Post Reply