등급 시스템을 만드는 방법에 대해 배우려는 about.com에서이 스크립트를 발견했지만 링크를 클릭하고 페이지를 다시로드 할 때 어떤 이유로 인해 스크립트가 투표에 포함되지 않습니다.PHP 및 MySQL 투표 수 문제가 있습니까?
이 문제를 어떻게 해결할 수 있습니까? 그리고 코드의 어느 부분을 변경해야합니까?
다음은 전체 스크립트입니다.
<?php
// Connects to your Database
mysql_connect("localhost", "root", "", "sitename") or die(mysql_error());
mysql_select_db("sitename") or die(mysql_error());
//We only run this code if the user has just clicked a voting link
if ($mode=="vote") {
//If the user has already voted on the particular thing, we do not allow them to vote again $cookie = "Mysite$id";
if(isset($_COOKIE[$cookie])) {
echo "Sorry You have already ranked that site <p>";
} else {
//Otherwise, we set a cooking telling us they have now voted
$month = 2592000 + time();
setcookie(Mysite.$id, Voted, $month);
//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
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
if($ratings['total'] > 0 && $ratings['votes'] > 0) {
$current = $ratings['total']/$ratings['votes'];
} else {
$current = 0;
}
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=?mode=vote&voted=1&id=".$ratings['id'].">Vote 1</a> | ";
echo "<a href=?mode=vote&voted=2&id=".$ratings['id'].">Vote 2</a> | ";
echo "<a href=?mode=vote&voted=3&id=".$ratings['id'].">Vote 3</a> | ";
echo "<a href=?mode=vote&voted=4&id=".$ratings['id'].">Vote 4</a> | ";
echo "<a href=?mode=vote&voted=5&id=".$ratings['id'].">Vote 5</a><p>";
}
?>
당신은이 사이트를 남용에 대한 투표를 내려 php.ini 파일에 ON = 있음을 확인해야합니다, PHP 옵션 register_globals의가 있다고 가정합니다, 당신은 이미 전에,이 코드를 한 시간에 한 번 붙여 당신은이 질문을 만들었습니다. 질문의 세부 사항을 변경하려면 원래 질문을 편집하고 새 질문을하지 말고 그냥 반복하십시오. – TravisO