Login form



Operations with file content, voting system, PART 9
File index.php


<?
$failas ="hits.txt";
$balsas = $_GET['balsas'];

if (@filesize($failas)==0){
$fp=fopen($failas, "w");
fwrite($fp, "-|0|0|0");
fclose($fp);
}          

if ($balsas){

$h=file($failas);
$hits=explode("|",$h[0]);

$hits[$balsas]++;
ksort ($hits);

$h=implode ("|",$hits);
$fp = fopen($failas, "w");
fwrite($fp, $h);
fclose($fp);
$viso =$hits[1] + $hits[2]+ $hits[3] ;

?><br><?
echo "1: ${hits[1]}" ;
?>
<hr color = red width="<?= 100 * $hits[1]/ $viso ;?>" align="left">
<?
echo "2: ${hits[2]}" ;
?>
<hr color = blue width="<?= 100 * $hits[2]/ $viso ;?>" align="left">
<?
echo "3: ${hits[3]}" ;
?>
<hr color = green width="<?= 100 * $hits[3]/ $viso ;?>" align="left">

<?
echo "<br>Viso $viso" ;
?>

<a href="/<? echo $_SERVER['PHP_SELF']; ?>" >atgal</a><?

}else{

?>

<form action="<? echo $_SERVER['PHP_SELF']; ?>" method="get">
1 <input type="radio" name="balsas" value="1"><br>
2 <input type="radio" name="balsas" value="2"><br>
3 <input type="radio" name="balsas" value="3"><br>
<input type=submit>
</form>

<?
}
?>

File hits.txt


-|4|10|38


Exercise 1 . Make it for 5 fields
Exercise 2.  Make it for dynamic amount of fields,   keeping field list adn descriptions on arrays.

 
[ BBC news ][ Yahoo news ][ Linux guru ][ Webmaster ACE ]