Jump to content

olivia

New Members
  • Posts

    1
  • Joined

  • Last visited

    Never

Profile Information

  • Gender
    Not Telling

olivia's Achievements

Newbie

Newbie (1/5)

0

Reputation

  1. [i]Q1:Create a calculator script that allows the user to submit two numbers and choose an operation to perform on them (addition, multiplication, division, subtraction). Q2:Use hidden fields with the script you created in exercise 1 to store and display the number of requests that the user has submitted.[/i] [b]the script which i found in other site:[/b] <?php /*Create a calculator script that allows the user to submit two numbers and choose an operation to perform on them (addition, multiplication, division, subtraction). Use hidden fields with the script you created in activity 1 to store and display the number of requests that the user has submitted.*/ $sum = array("add\"=>($fnum + $snum), // stores calculations \"subtract\"=>($fnum-$snum), \"multiply\"=>($fnum*$snum), \"divide\"=>($fnum/$snum)); $submissions = (isset($submissions))?++$submissions:0; // keeps track of how many times user has clicked calculate if ( (!isset($fnum)) || (!isset($snum)) ) // if nothing is set for both number values print welcome message. { $message = \"Welcome to the calculation script!\"; } if ( (!isset($fnum)) && (isset($snum)) ) { $message = \"Value is missing in the first number field.\"; } if ( (isset($fnum)) && (!isset($snum)) ) { $message = \"Value is missing in the second number field.\"; } if ( (isset($fnum)) && (isset($snum)) ) // if both first and second number have a value { if ($operation[\"addition\"]==\"addition\") { $message = $sum[\"add\"]; } if ($operation[\"subtraction\"]==\"subtraction\") { $message = $num[\"subtract\"]; } if ($operation[\"multiplication\"]==\"multiplication\") { $message = $num[\"multiply\"]; } if ($operation[\"division\"]==\"division\") { $message = $num[\"divide\"]; } } ?> <html> <head> <title>Testing Page</title> <link rel=\"stylesheet\" type=\"text/css\" href=\"http://www.mavurik.net/content/layout/css/mavurik.css\"> <body> <p><b><?php print $message?></b></p> <p> </p> <p>You have used the calculator <?php print $submissions?> times.</p> <form action=\"<?php print $PHP_SELF?>\" method=\"POST\"> <p>First Number: <input type=\"text\" name=\"fnum\" value=\"<?php print $fnum?>\"></p> <p>Second Number: <input type=\"text\" name=\"snum\" value=\"<?php print $snum?>\"></p> <p> </p> <p>Please select an operation method:</p> <select name=\"operation[]\"> <option>addition <option>subtraction <option>multiplication <option>division </select> <p> </p> <input type=\"hidden\" name=\"submissions\" value=\"<?php print $submissions?>\"> <p><input type=\"submit\" value=\"calculate!\"></p> </form> </body> </html> [b]But it doesn't work.[/b] help me please.
×
×
  • 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.