又是我。我保证在这之后我不会打扰你一段时间了!:)
我有这个评级系统,它允许用户对文章进行评级。它有点工作,但问题是它不会更新数据库中的数据,我不知道为什么。任何帮助,将不胜感激。 :)
// Connects to your Database
mysql_connect("URL", "username", "password") or die(mysql_error());
mysql_select_db("db_name") or die(mysql_error());
//Then we update the voting information by adding 1 to the total votes and adding their vote (1,2,3,etc) to the total rating
if(isset($_submit['voted'])) {
mysql_query ("UPDATE vote SET total= total+$voted, votes = votes+1 WHERE id = $id");
Echo "Your vote has been cast <p>";
}
//Puts SQL Data into an array
$data = mysql_query("SELECT * FROM vote") or die(mysql_error());
//Now we loop through all the data
while($ratings = mysql_fetch_array( $data ))
{
//This outputs the sites name
Echo "Name: " .$ratings['name']."<br>";
//This calculates the sites ranking and then outputs it - rounded to 1 decimal
$current = $ratings['total'] / $ratings['votes'];
Echo "Current Rating: " . round($current, 1) . "<br>";
//This creates 5 links to vote a 1, 2, 3, 4, or 5 rating for each particular item
Echo "Rank Me: ";
Echo "<a href='index.php?site=kumu'?mode=vote&voted=1&id=".$ratings['id'].">1</a> | "; //The HREF was ".$_SERVER['PHP_SELF']." before
Echo "<a href='index.php?site=kumu'?mode=vote&voted=2&id=".$ratings['id'].">2</a> | ";
Echo "<a href='index.php?site=kumu'?mode=vote&voted=3&id=".$ratings['id'].">3</a> | ";
Echo "<a href='index.php?site=kumu'?mode=vote&voted=4&id=".$ratings['id'].">4</a> | ";
Echo "<a href='index.php?site=kumu'?mode=vote&voted=5&id=".$ratings['id'].">5</a><p>";
}
?>
谢谢大家!:)
最佳答案
替换此行
if(isset($_submit['voted'])) {
mysql_query ("UPDATE vote SET total= total+$voted, votes = votes+1 WHERE id = $id");
echo "Your vote has been cast <p>";
}
有了这个
if(isset($_POST['voted'])) {
mysql_query ("UPDATE vote SET total= total+$voted, votes = votes+1 WHERE id = $id");
echo "Your vote has been cast <p>";
}
关于php - 数据库中的信息未更新,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20425185/