Contoh2_5.php
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01
Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title> :::
Operasi Aritmatika ::: </title>
</head>
<body>
<form
action=operasi.php method=get>
<center><h3>Operasi Aritmatik A
dan B</h3></center>
<table
align=center bgcolor=#cedadc bordercolor=#cfdbdd>
<tr>
<td> Masukan Nilai A </td>
<td><input type=text name=a
size=10></td>
</tr>
<tr>
<td> Masukan Nilai B </td>
<td><input type=text name=b
size=10></td>
</tr>
<tr>
<td> Operasi </td>
<td>
<select name=c>
<option value=1> Penjumlahan [a+b]
</option>
<option value=2> Pengurangan [a-b]
</option>
<option value=3> Perkalian [a*b]
</option>
<option value=4> Pembagian [a/b] </option>
</select>
</td>
</tr>
<tr>
<td colspan=2 align=center>
<input type=submit
value=hitung></td>
</tr>
</table>
</form>
</body>
</html>
File operasi.php
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01
Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title> Hasil
Operasi Aritmatik </title>
</head>
<body>
<?
$operasi=$_GET['c'];
$a=$_GET['a'];
$b=$_GET['b'];
if
($operasi==1)
{
$c=$a
+ $b;
$oper='[a+b]';
}
elseif
($operasi==2)
{
$c=$a
- $b;
$oper='[a-b]';
}
elseif
($operasi==3)
{
$c=$a
* $b;
$oper='[a*b]';
}
else
{
$c=$a
/ $b;
$oper='[a/b]';
}
echo
"Nilai A adalah = $a dan Nilai B adalah = $b <br>";
echo
"Nilai Operasi $oper adalah = $c <br>";
?>
</body>
</html>