
Originally Posted by
StrongFaith
Hello Ragezoners , i made a calculator , its VERY SIMPLE tho , dont flame me.
so here it is !
PHP Code:
<h1>Simple calculator - Usable</h1>
<h3>Source by foxx - thank you and edited by StronGCoder</h3>
<?php
// source by foxx - thanks!
// edited by strong
// advanced calculator coming soon!
$result = "";
if (isset($_POST['val'])) {
$val = (float)$_POST['val'];
$val2 = (float)$_POST['val2'];
if (!$val and $val2) {
$result .= "<p>Fill all fields , please!</p>";
}
if (!$result) {
switch ($_POST['operator']) {
case "sum":
$result = $val.'+'.$val2.' = '.$val+$val2;
break;
case "sub":
$result = $val.'-'.$val2.' = '.$val-$val2;
break;
case "mul":
$result = $val.'*'.$val2.' = '.$val*$val2;
break;
case "div":
$result = $val.'/'.$val2.' = '.$val/$val2;
break;
}
}
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="cz" lang="cz">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<meta http-equiv="Content-Language" content="en" />
<title>Calculator by StronGCoder</title>
</head>
<body>
<form method="post" action="/calculator/index.php">
<dl>
<label for="val"></label>
<input type="text" name="val" id="val" value='First number' />
<label for="operator"></label>
<select name="operator" id="operator">
<option value="Choose">Choose one :</option>
<option value="sum">+</option>
<option value="sub">-</option>
<option value="mul">*</option>
<option value="div">/</option>
</select>
</dd>
<label for="val2"></label>
<input type="text" name="val2" id="val2" value='Second number' />
<input type="submit" name="submit" value='Calculate' />
</dl>
</form>
<?php
echo $result;
?>
</body>
</html>
credits
50% - foxx - the base source
50% - me - coding , fixing , editing !
thanks!

To repeat what I've said the in the other thread.
There is not a single thing you've "fixed", in fact, you've, sadly, fokked it up.
To go through it.
PHP Code:
<h1>Simple calculator - Usable</h1>
<h3>Source by foxx - thank you and edited by StronGCoder</h3>
this shouldn't be there, not before the <html> tag, not before <?php ?>
PHP Code:
if (!$val and $val2) {
$result .= "<p>Fill all fields , please!</p>";
}
This doesn't make sense, it would throw error ONLY if you didn't fill value 1 but you did fill value 2.
PHP Code:
<form method="post" action="/calculator/index.php">
"/" would be perfectly fine
PHP Code:
<dl>
<label for="val"></label>
<input type="text" name="val" id="val" value='First number' />
<label for="operator"></label>
<select name="operator" id="operator">
<option value="Choose">Choose one :</option>
<option value="sum">+</option>
<option value="sub">-</option>
<option value="mul">*</option>
<option value="div">/</option>
</select>
</dd>
<label for="val2"></label>
<input type="text" name="val2" id="val2" value='Second number' />
</dl>
<dl> is a definiton list, it wrap dt and dd elements, it requires at least one dt, you've deleted all dt and dd and only left one dd closing tag (</dd>), so it wouldn't validate and probably will be fokked up in most of the browsers..
labels are.. well labels, why leave them there when you deleted the text inside them?
You see, you took my source and messed it up, that's why I said hopeless.
No need to give me any credit there, really, someone could of thought I made this mess.