-
Problems
This line enable URL Rewriting . It must be enabled via the RewriteEngine directive! and if your .htaccess file is going to use rewrite rules, you should always include this line. Otherwise, you can’t be sure if its enabled or not. The string “on” is case insensitive.
<h1>The Calculator</h1>
<h3>Version 1.3</h3>
<p>Important: Use the radian equivalent to the number when getting cos, sin and tan.</p>
<hr>
<h2>Simple</h2>
<form action="" method="post">
<input name="first" type="text" size="6" maxlength="10">
<select name="method1">
<option value="add" selected>Add</option>
<option value="sub">Subtract</option>
<option value="multi">Multiply</option>
<option value="div">Divide</option>
</select>
<input name="second" type="text" size="6" maxlength="10">
<br><br>
<input name="submit1" type="submit" value="Calculate">
</form>
<?php
// Get variables from POST:
if (isset($_POST['submit1']) ) {
$submit1 = $_POST['submit1'];
$method1 = $_POST['method1'];
$first = $_POST['first'];
$second = $_POST['second'];
switch ($method1) {
case "add": $ans = $first + $second;
break;
case "sub": $ans = $first - $second;
break;
case "multi": $ans = $first * $second;
break;
case "div": $ans = $first / $second;
break;
}
$ans = number_format($ans, 2, ',', ' ');
echo "<p>The answer is $ans</p>";
}
?>
<hr>
<h2>Advanced</h2>
<form action="" method="post">
<input name="number" type="text" size="6" maxlength="10">
<select name="method2">
<option value="cos">Get cosine</option>
<option value="sin">Get sine</option>
<option value="tan">Get tangent</option>
<option value="decbin">Decimal to binary</option>
<option value="bindec">Binary to decimal</option>
<option value="dechex">Decimal to hexadecimal</option>
<option value="hexdec">Hexadecimal to decimal</option>
<option value="deg2rad">Degree to radian</option>
<option value="rad2deg">Radian to degree</option>
</select>
<br>
<br>
<input name="submit2" type="submit" value="Calculate">
</form>
<?php
if (isset($_POST['submit2'])) {
$method2 = $_POST['method2'];
$number = $_POST['number'];
switch ($method2) {
case "cos": $ans = cos($number);
break;
case "sin": $ans = sin($number);
break;
case "tan": $ans = tan($number);
break;
case "decbin": $ans = decbin($number);
break;
case "bindec": $ans = bindec($number);
break;
case "dechex": $ans = dechex($number);
break;
case "hexdec": $ans = hexdec($number);
break;
case "deg2rad": $and = deg2rad($number);
break;
case "rad2deg": $ans = rad2deg($number);
break;
}
echo "<p>The answer is $ans</p>";
}
?>
No comments:
Post a Comment