Jump to content

my first PHP script, form not returning output


CherryLips

Recommended Posts

Hello, I am completely new to PHP and taking at the community college. My first assignment was to create a form and so I decided to create a calculation form. My problem is that it isnt returning any output and I think there may be an issue with the submit button.

 

I am using xampp and I also have dreamweaver connected to my server. I haven't quite fifured out the error reporting for apache, but dreamweaver is giving no syntax errors.

 

The link to my form is http://www.cherrycreatives.com/php/calculate_form.html and http://www.cherrycreatives.com/php/calculate.php

 

Here is the code for each file(they are also attached):

 

 

<!doctype html>
<html>
<head>
<meta charset="UTF-8">
<title>PHP Form by Carrie Carrigan</title>
</head>
<body>
<form method="post" action="calculate.php">
<p>Value: 1 <input type="text" name="val1" size=10></p>
<p>Value: 2 <input type="text" name="val2" size=10></p>
<p>Calculation:</p>
<input type="radio" name="calc" value="add"> add <br>
<input type="radio" name="calc" value="subtract"> subtract <br>
<input type="radio" name="calc" value="multiply"> multiply <br>
<input type="radio" name="calc" value="divide"> divide <br></p>
<p><input type="button" name="submit" value="calculate">
</p></form>
</body>
</html>

 

-------------------------------------------------------------------------------

 

<!doctype html>
<html>

<head>
<meta charset="UTF-8">
<title>Calculation Result</title>
</head><?php
if (($_POST[val1] == "") || ($_POST[val2] == "") || ($_POST[calc] == '')) {
    header("Location: calculate_form.html");
    exit;
}
if ($_POST[calc] == "add") {
    $result = $_POST[val1] + $_POST[val2];
}
else if ($_POST[calc] == "subtract") {
    $result = $_POST[val1] - $_POST[val2];
}
else if ($_POST[calc] == "multiply") {
    $result = $_POST[val1] * $_POST[val2];
}
else if ($_POST[calc] == "divide") {
    $result = $_POST[val1] / $_POST[val2];
}
?>
<body>
<p>The result of the calculation is: <?php echo "$result";
?></p>
</body>
</html>

calculate.php

calculate_form.html

 

 

I haven't quite fifured out the error reporting for apache, but dreamweaver is giving no syntax errors.

Not Apache you want to configure, but PHP. You need to open php.ini and set error_reporting to E_ALL and set display_errors to ON. Make sure you restart apache after any changes to the php.ini

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.