PHPで作った簡易投票システムの例の問題点
Webページ上で投票しても投票数は変わらないが、データベース内の投票を書き換えるとWebページ上の投票数が変わってしまうそれに応じて変更されます
コードは次のとおりです:
<!-- Code highlighting produced by Actipro CodeHighlighter (freeware) http://www.CodeHighlighter.com/ --><?if($voted && $already_voted){$SetCookie("already_voted","1");}?> <html> <head><title>线上投票系统</title></head> <body> <font size=5 color=#0000ff>线上投票系统</font><br><p> 主题:我们选举的班长 <form action="<?echo $PHP_SELF?>" method="POST"> <? mysql_pconnect("LocalHost","root","wuhong"); if($voted && $already_voted) { print("<font size=4 color=#ff0000>你已投上神圣的一票!</font><br><p>\n"); } else if($voted) { if(!mysql_db_query("xyl","update vote_banzhang set vote_number=vote_number+1 where votee='$voted'")) { print mysql_erron().":".mysql_error()."<br>"; } }$result=mysql_db_query("xyl","select sum(vote_number) as sum from vote_banzhang"); if($result) { $sum=(int)mysql_result($result,0,"sum"); mysql_free_result($result); } $result=mysql_db_query("xyl","select * from vote_banzhang order by vote_number DESC"); print "<table border=0><tr><td>选取</td><td>我们的班长</td><td>票数</td></tr>\n"; while($row=mysql_fetch_row($result)) { //print "<tr><td align=center><iput type=radio name=voted value=\"$row[0]\"></td>td>"; //print $row[0]."</td><td align=right>".$row[1]."</td><td>"; //print "</tr>\n"; //print "</table>\n";0 $votee=$row[0];$vote_numbers=$row[1];?> <tr><td align=center> <input type=radio name="voted" value=$row[0]></td> <td> <? echo $row[0]?></td> <td align=right><? echo $row[1]?></td> </tr> <? } ?> </table> <? mysql_free_result($result); ?> <input type=submit value="投票了!"> <input type=reset value="我要重选"> </form> </body> </html>