Home  >  Article  >  Backend Development  >  一个php做的简易的投票系统例子出现的有关问题

一个php做的简易的投票系统例子出现的有关问题

WBOY
WBOYOriginal
2016-06-13 13:23:031014browse

一个php做的简易的投票系统例子出现的问题
在网页投票后没有票数没有变化,但在数据库里改写票数,网页票数相应变化

代码如下:

PHP code
<!--

Code highlighting produced by Actipro CodeHighlighter (freeware)
http://www.CodeHighlighter.com/

--><?if ($voted && $already_voted){$SetCookie("already_voted","1");}?>

    <title>线上投票系统</title>
    
    <font size="5" color="#0000ff">线上投票系统</font><br><p>
    主题:我们选举的班长
    </p>
mysql_pconnect("LocalHost","root","wuhong"); if($voted && $already_voted) { print("你已投上神圣的一票!

\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()."
"; } }$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 "

\n"; while($row=mysql_fetch_row($result)) { //print "td>"; //print $row[0]."\n"; //print "
选取 我们的班长 票数
".$row[1]." "; //print "
\n";0 $votee=$row[0];$vote_numbers=$row[1];?> echo $row[0]?> echo $row[1]?> } ?> mysql_free_result($result); ?>
数据库中只有一个表 vote_banzhang(votee varchar(12),vote_numbers int(4)主码)

------解决方案--------------------
顺藤摸瓜调试就可以了。
输出POST值看看得到没有;
再看看mysql连接成功没;
看看查询执行有效不;
------解决方案--------------------
你并没有说清除你到底遇到了什么麻烦
给代码最上面加上一行 error_reporting(E_ALL | E_NOTICE); 。打开错误提示,看看报什么错误,然后都贴出来

另外粗略的看了一下 $SetCookie("already_voted","1"); 这是什么?

------解决方案--------------------
数据没有存到数据库里去,应该是没有接收到值,你们做一个IF判断吧,判断有没有接到值再村数据库
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn