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.


<html>

<head>
<title>Matematic executions</title>

</head>

<body>

<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

<br><hr>

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

</form>     

</body>

</html>



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
<html>
<head>
</head>
<body>
<?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"); }   
?>
</body>
</html>


views 10118
  1. Add New Comment