<html>
<head>
<meta http-equiv="content-type" content="text/html;charset=utf-8" />
</head>
<body>
<?php
$votes=array("zhangsan"=>0,"lisi"=>0,"wangwu"=>0);
if(file_exists("votes.dat"))
{
$fp=fopen("votes.dat","r");
$tmp=fread($fp, 2048);
$votes=unserialize($tmp);
fclose($fp);
}
else
{
$fp=fopen("votes.dat","w");
fwrite($fp, serialize($votes));
fclose($fp);
}
if(isset($_POST["sb"]))
{
if(isset($_POST["choice"]))
{
$cc=$_POST["choice"];
switch($cc)
{
case "zhangsan":
$votes["zhangsan"]++;
break;
case "lisi":
$votes["lisi"]++;
break;
case "wangwu":
$votes["wangwu"]++;
break;
default:
break;
}
}
$fp=fopen("votes.dat","w");
fwrite($fp, serialize($votes));
fclose($fp);
}
?>
<form name="form1" action="" method="post">
<div><span>总统候选人:</span></div>
<div><input type="radio" name="choice" value="zhangsan"/>张三<br />
<input type="radio" name="choice" value="lisi" />李四<br />
<input type="radio" name="choice" value="wangwu" />王五
</div>
<div><input type="submit" name="sb" value="投票" /></div>
<div>张三的票数:<span><?php echo $votes["zhangsan"];?></span></div>
<div>李四的票数:<span><?php echo $votes["lisi"];?></span></div>
<div>王五的票数:<span><?php echo $votes["wangwu"];?></span></div>
<div>总票数:<span><?php ?></span></div>
</form>
</body>
</html>
<head>
<meta http-equiv="content-type" content="text/html;charset=utf-8" />
</head>
<body>
<?php
$votes=array("zhangsan"=>0,"lisi"=>0,"wangwu"=>0);
if(file_exists("votes.dat"))
{
$fp=fopen("votes.dat","r");
$tmp=fread($fp, 2048);
$votes=unserialize($tmp);
fclose($fp);
}
else
{
$fp=fopen("votes.dat","w");
fwrite($fp, serialize($votes));
fclose($fp);
}
if(isset($_POST["sb"]))
{
if(isset($_POST["choice"]))
{
$cc=$_POST["choice"];
switch($cc)
{
case "zhangsan":
$votes["zhangsan"]++;
break;
case "lisi":
$votes["lisi"]++;
break;
case "wangwu":
$votes["wangwu"]++;
break;
default:
break;
}
}
$fp=fopen("votes.dat","w");
fwrite($fp, serialize($votes));
fclose($fp);
}
?>
<form name="form1" action="" method="post">
<div><span>总统候选人:</span></div>
<div><input type="radio" name="choice" value="zhangsan"/>张三<br />
<input type="radio" name="choice" value="lisi" />李四<br />
<input type="radio" name="choice" value="wangwu" />王五
</div>
<div><input type="submit" name="sb" value="投票" /></div>
<div>张三的票数:<span><?php echo $votes["zhangsan"];?></span></div>
<div>李四的票数:<span><?php echo $votes["lisi"];?></span></div>
<div>王五的票数:<span><?php echo $votes["wangwu"];?></span></div>
<div>总票数:<span><?php ?></span></div>
</form>
</body>
</html>