Here's one that works... Note: you may want to add a two second wait after the cookies reset so that the reload after the reset displays correctly.
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<meta http-equiv="content-type" content="text/html; charset=utf-8" />
<title>procnum.php</title>
</head>
<body>
<?php
define ('BRC', '<br />');
if (isset($_POST['n']))
{
$n=$_POST['n'];
if ( (isset($_COOKIE['max'])) &&
(isset($_COOKIE['min'])) &&
(isset($_COOKIE['med'])) &&
(isset($_COOKIE['tot'])) &&
(isset($_COOKIE['cont']))
)
{
$max= $_COOKIE['max'];
$min= $_COOKIE['min'];
$med= $_COOKIE['med'];
$tot= $_COOKIE['tot'];
$cont=$_COOKIE['cont'];
if ($n>$max) { $max=$n; }
if ($n<$min) { $min=$n; }
$cont++;
$tot += $n;
$med=$tot/$cont;
setcookie("max", $max);
setcookie("min", $min);
setcookie("med", $med);
setcookie("tot", $tot);
setcookie("cont", $cont);
echo "<hr />";
echo "Minimo :" . $min . BRC;
echo "Massimo :" . $max . BRC;
echo "Media :" . $med . BRC;
echo "Conteggio :" . $cont . BRC;
}
else
{
setcookie("max", $n);
setcookie("min", $n);
setcookie("med", $n);
setcookie("tot", $n); ## This line was not in original script
setcookie("cont", 1);
}
}
if (isset($_POST['reset']))
{
setcookie("max", "", time()-3600);
setcookie("min", "", time()-3600);
setcookie("med", "", time()-3600);
setcookie("tot", "", time()-3600);
setcookie("cont", "", time()-3600);
}
?>
<form name="num" id="num" method="post" action="<?php echo $_SERVER['PHP_SELF']; ?>" >
<fieldset><legend>Entre un numero:</legend>
<label for="n">Numero</label><br />
<input name="n" id="n" type="text" size=6 maxlength=6 />
</fieldset>
<input name="submit" id="submit" type="submit" value="Aggiorna!" />
<input name="reset" id="reset" type="submit" value="Vacie los datos almacenados" />
</form>
</body>
</html>
-- User404