Manipulating of given values

Mar 03, 2011 Author: Dusan

The HTML script in the example above is giving to the client to put two numbers and after that to choose matematic operation, which will be provided. When the script will be put on server, theese values are sending on PHP scrip for processing, and the name of the PHP script is matematic.php.


<title>Matematic executions</title>



<h2>Execute matematic operations with number</h2> <hr>

<form action="matematic.php" method="post">

<b>Please enter number</b>

<input type="text" name="value" size="5"><br><br>

<b>Choose one matematic operation</b>:

<input type="radio" name="operation" value="k_kv">Square root

<input type="radio" name="operation" value="squere">Raising the square


<input type="submit" value="Execute">




The PHP script for processing the HTML document is using the function is_numeric(), and this function is used to check is there number value in the field.
example matematic.php
$value = $_POST['value'];    
$operation = $_POST ['operation'];    
if (is_numeric($value))    
{ if ($operation!=null)    
{ switch ($operation )    
{ case "k_kv":$result = sqrt($value);    break;       
case "squere":$result = $value * $value; break; }    
echo ("The result is: $result" );        } 
else { echo ("Invalid value"); }   

views 9785
  1. Add New Comment