我这是一个投票系统我提出,这个代码显示了用户的问题的列表,他们可以从这里选择:资源ID#6误差在PHP与MySQL
<div class="main_questions">
<p class="style1 style2"><strong>Select Your Question</strong></p>
<p class="style1">
<form action="vote_list.php" method="post" name="form1" class="style1">
<?php
$sql = "SELECT DISTINCT (question_tba) FROM question ORDER BY answer_id DESC";
$result = mysql_query($sql);
while($row = mysql_fetch_array($result)){
?>
<p>
<?php echo $row['question_tba']; ?>
<input type="radio" name="questions" value="<?php echo $row['question_tba']; ?>">
</p>
<?php
}
?>
<input type="submit" name="submit" value="Vote">
</p>
</div>
此代码应再交所选择的问题,此页面允许他们投上一票:使用这些功能由1
<?php
include('core/initialise.inc.php');
$q = $_POST['question_tba'];
if (isset($_GET['vote'], $_GET['id'])){
add_vote($_GET['id'], $_GET['vote'], $q);
echo "<META HTTP-EQUIV=\"REFRESH\" CONTENT=\"0; URL=vote_logged.php\">";
}
?>
</div>
<div class="main_questions">
<p class="style1 style2"><strong>Place Your Vote!</strong></p><?php
foreach (get_answers($q) as $id => $answer){
?>
<p>
<?php echo $answer; ?>
<a href="?vote=up&id=<?php echo $id; ?>">Vote</a>
</p>
<?php
}
?>
</div>
然后,当他们点击一个答案,这个页面应该增加所选择的答案投票功能表决:
<?php
function get_answers($q){
$q = $q;
$sql = "SELECT answer_id, answer FROM question WHERE question_tba = '$q'";
$result = mysql_query($sql);
echo "$result";
$answers = array();
while (($row = mysql_fetch_assoc($result)) or die(mysql_error()))
{
$answers[$row['answer_id']] = $row['answer'];
}
return $answers;
}
function add_vote($answer_id, $vote, $q2){
$q2 = $q2;
$answer_id = (int)$answer_id;
$vote = '+';
$sql = "UPDATE question SET answer_votes = answer_votes $vote 1 WHERE question_tba = $q2 AND answer_id = $answer_id";
mysql_query($sql);
}
?>
但是,我的问题是,当我点击我想投票的问题时,而不是显示我可以选择投票的答案,它只是显示资源ID#6。任何人都可以告诉我我的代码有什么问题吗?
欢迎来到Stack Overflow!作为一个方面说明,你没有在你的查询中进行错误检查。如果你不这样做,如果查询失败,脚本将中断。如何做适当的错误检查在[mysql_query()'](http://php.net/mysql_query)手册中或在这个[参考问题]中列出(http://stackoverflow.com/questions/6198104/reference-what-is-a-perfect-code-sample-using-the-mysql-extension) – 2012-03-08 13:49:49
请指定哪一行准确输出该文本 – 2012-03-08 13:50:17