Closed Thread
Results 1 to 4 of 4

Thread: Simple Calculator PHP Need Help!

  1. #1
    dquigley's Avatar
    dquigley is offline x10 Sophmore dquigley is an unknown quantity at this point
    Join Date
    Sep 2008
    Location
    Fresno, CA
    Posts
    249

    Simple Calculator PHP Need Help!

    I am creating a script from a book that is teaching me php and I am having an issue with this calculator script, it apears to be working but if I click submit I get the error
    Forbidden

    You don't have permission to access /calculate.php" on this server.
    The first html script is

    <HTML>
    <HEAD>
    <TITLE>Calculation Form</TITLE>
    </HEAD>
    <BODY>

    <FORM METHOD="post" ACTION=calculate.php">
    <P>Value 1: <INPUT TYPE="text" NAME="va11" SIZE=10></P>
    <P>Value 2: <INPUT TYPE="text" NAME="va12" 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>
    And the second script the php part is

    <?

    if (($_POST[va11] =="") || ($_POST[va12] =="") || ($_POST[calc] =="")) {
    header ("Location: calculate_form.html");
    exit;
    }
    if ($_POST[calc] == "add") {
    $result = $_POST[va11] + $_POST[va12];
    } else if ($_POST[calc] == "subtract") {
    $result = $_POST[va11] - $_POST[va12];
    } else if ($_POST[calc] == "multiply") {
    $result = $_POST[va11] * $_POST[va12];
    } else if ($_POST[calc] == "divide") {
    $result = $_POST[va11] / $_POST[va12];
    }

    ?>
    <HTML>
    <HEAD>
    <TITLE>Calculation Result</TITLE>
    </HEAD>
    <BODY>

    <P>The result of the calculation is: <? echo "$result"; ?></P>

    </BODY>
    </HTML>
    Edit:
    Sorry, nevermind after looking at my post for a minute I found the error
    Ill post it in case any of you are trying to learn too or are curious.

    Heres the error from the first html script
    <FORM METHOD="post" ACTION=calculate.php">
    Heres how I fixed it
    <FORM METHOD="post" ACTION="calculate.php">
    Last edited by dquigley; 12-10-2008 at 09:52 PM. Reason: Automerged Doublepost

  2. #2
    cursedpsp is offline x10 Sophmore cursedpsp is an unknown quantity at this point
    Join Date
    Apr 2008
    Location
    Wiltshire, England
    Posts
    238

    Re: Simple Calculator PHP Need Help!

    "$_POST[va11]" etc.. The va1x should be wrapped up in single quotes also, since they are strings. Ints dont need to be.

  3. #3
    tttony's Avatar
    tttony is offline x10 Sophmore tttony is an unknown quantity at this point
    Join Date
    Jan 2008
    Location
    ~ 10°10'27.10''' N 67°59'59'.59''' O elev. 457m
    Posts
    147

    Re: Simple Calculator PHP Need Help!

    yes, $_POST[va11] to $_POST['va11']
    PHP & MySQL Web Developer
    Free Domain co.cc

  4. #4
    compwhizii is offline Banned compwhizii is an unknown quantity at this point
    Join Date
    May 2008
    Location
    The Moon
    Posts
    779

    Re: Simple Calculator PHP Need Help!

    Since this is resolved I'm going to close.

Closed Thread

Similar Threads

  1. Two very simple php file upload scripts-Free
    By Symbian.Ankit in forum Scripts & 3rd Party Apps
    Replies: 2
    Last Post: 02-20-2008, 09:55 AM
  2. Simple Forum Sig Tutorial (Photoshop)
    By Veivei in forum Graphics & Webdesign
    Replies: 7
    Last Post: 09-05-2007, 09:34 PM
  3. simple script
    By swirly in forum Scripts & 3rd Party Apps
    Replies: 10
    Last Post: 06-17-2006, 06:32 PM
  4. [PS] Making Simple Borders
    By moose in forum Tutorials
    Replies: 0
    Last Post: 03-22-2006, 08:20 AM
  5. New Simple Sig
    By phenetic in forum Graphics & Webdesign
    Replies: 2
    Last Post: 02-23-2005, 08:29 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
x10hosting free hosting for the masses
dedicated servers