View Single Post
  #1  
Old 25th Jun 03, 07:26 PM
adams adams is offline
Super Moderator
 
Join Date: Jul 2001
Posts: 1,124
adams is an unknown quantity at this point
bought a book to help me learn php. i type the code directly from the book and save it in the root directory on my computer, but then when i type in the address in my browser, the page will load but not work like it is supposed to.

here is the code for both pages. (its just a simple calculation script).
calculate.php:
Code:
<? if (($_POST[val1] == "") || ($_POST[calc] =="")) { header("Location: http://127.0.0.1/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]; } ?> <HTML> <HEAD> <TITLE> Calculation and Result</TITLE> </HEAD> <BODY> <P>The result of the calculation is: <? echo "$result"; ?></P> </BODY> </HTML>
calculate_form.html:
Code:
<HTML> <HEAD> <TITLE>Calculation Form</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:<br> <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</P> <P><INPUT TYPE="submit" NAME="submit" VALUE="Calculate"></P> </FORM> </BODY> </HTML>
whenever i enter the two values in the blanks and choose to add (or whatever) and click submit, the page just reloads itself.
thanks in advance.
__________________
Camera Equipment:
Canon 40D & Digital Rebel XT
Canon 500mm L IS USM
Canon 100-400mm L IS USM
kit lens
Sigma 70-300mm APO DG
Canon 430 EX Speedlight
Dynatran Tripod
Lowepro Mini Trekker AW backpack
Reply With Quote