简单的PHP投票系统 [英] Simple PHP Voting System

查看:282
本文介绍了简单的PHP投票系统的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个简单的应用程序,它允许用户提交问题",然后对其进行评论.我试图建立一个简单的投票系统,以便用户可以投票"解决问题,从而将他们推向更高的位置.我已经掌握了PHP的一些基本知识,并且到目前为止一切正常,但我只是想不出如何使它正常工作.

I have a simple application which allows users to submit 'problems' and then comment on them. I am attempting to make a simple voting system so users can 'vote up' problems which in turn will push them higher up a list. I have some basic knowledge of PHP and everything so far is working, I just can't figure out how to get this to work.

我已经在线上学习了一个教程,到目前为止,在我的problem.php页面上有此内容...

I've followed a tutorial online and so far have this on my problem.php page...

if (isset($_GET['vote'], $_GET['id'])){
        add_problem_vote($_GET['id]'], $_GET['vote']);
    }

<a href="?vote=up&amp;id=<?php echo $problemID; ?>">Vote</a>

在我的functions.php页面上...

And on my functions.php page...

function add_problem_vote($problemID, $vote){

    $problemID = (int)$problemID;

    $vote = ($vote === 'up') ? '+' : '-';

    $sql = "UPDATE `problems` SET `votes` = `votes` {$vote} 1 WHERE `id` = {$problem_id}";

    mysql_query($sql);
}

我所有的表字段都绝对正确命名.我知道有很多事情需要考虑,例如在会议闭幕后重新投票,但是只要我已经表明它不一定是完美的.在单击链接的那一刻,它会重定向到页面,但mysql表中的票数没有变化.

All my table fields are definitely named correctly. I know there are many things to consider like re-voting after the session has closed but as long as I have shown the idea it doesn't have to be perfect. At the minute when the link is clicked it redirects to a page but the votes don't change in the mysql table.

推荐答案

$sql = "UPDATE `problems` SET `votes` = `votes` ".$vote." 1 WHERE `id` = ".$problem_id;
mysql_query($sql) or die(mysql_error());

检查您遇到什么错误?

这篇关于简单的PHP投票系统的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆