-- Mar 3 In-Class Exercise
<!DOCTYPE HTML>
<html>
<head>
<style>
</style>
</head>
<body>
<?php
$num = "";
if($_SERVER["REQUEST_METHOD"] == "POST") {
global $num = addNum($_POST["num"]);
}
function addNum($n) {
$file = fopen("count.txt", "a+") or die("File not open");
$n = fread($file, filesize("coutn.txt"));
$sum = $n + $num;
fwrite($file, $sum);
fclose($file);
return $sum;
}
?>
<form method="post" action="<?php echo htmlspecialchars($_SERVER["PHP_SELF"]);?>">
Add: <input type="text" name="num" value="<?php echo $num;?>">
<input type="button" onclick="addNum($num)" value="submit">
</form>
<?php
echo "Add to number: ";
echo addNum;
?>
</body>
</html>
<!DOCTYPE HTML>
<html>
<head>
<style>
</style>
</head>
<body>
<?php
$num = "";
if($_SERVER["REQUEST_METHOD"] == "POST") {
global $num = addNum($_POST["num"]);
}
function addNum($n) {
$file = fopen("count.txt", "a+") or die("File not open");
$n = fread($file, filesize("coutn.txt"));
$sum = $n + $num;
fwrite($file, $sum);
fclose($file);
return $sum;
}
?>
<form method="post" action="<?php echo htmlspecialchars($_SERVER["PHP_SELF"]);?>">
Add: <input type="text" name="num" value="<?php echo $num;?>">
<br />
<input type="button" onclick="addNum($num)" value="submit">
</form>
<?php
echo "Add to number: ";
echo addNum;
?>
</body>
</html>