php - 数据库中的信息未更新

标签 php mysql

又是我。我保证在这之后我不会打扰你一段时间了!:)

我有这个评级系统,它允许用户对文章进行评级。它有点工作,但问题是它不会更新数据库中的数据,我不知道为什么。任何帮助,将不胜感激。 :)

// 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/

相关文章:

javascript - PHP - 如何将错误消息返回到注册页面

mysql - 为什么 MySQL 存储过程将 X 日期时间转换为 NAME_CONST?

javascript - Laravel 5.2 - 在 ajax 请求后从 Controller 返回 View

PHP move_uploaded_file 权限被拒绝(权限设置为 755)

php - fatal error : Class not Found when using namespaces

php - 日期+时间的API响应格式(iso thing?)

javascript - 为什么我在更新 mysql 的 where 子句中出现错误

mysql - 如何用多次出现的模式填充 varchar

MYSQL:插入错误

python - 将 Python 与 MySQL 结合使用