Jump to content

my first PHP script, form not returning output


CherryLips
Go to solution Solved by Barand,

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

Link to comment
Share on other sites

 

 

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

Edited by Ch0cu3r
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.