Jump to content

[SOLVED] Rating script


dropfaith

Recommended Posts

okay so this connects elsewhere on my page and is pulling the data just fine the error im getting is

Notice: Undefined variable: mode in /home/www/lawrenceguide.org/www/recipes/profile.php on line 184

also its not updating if a person votes but i assume the Notice has something to do with that

 

<?php
//Puts SQL Data into an array
$data = mysql_query("SELECT * FROM RecipeVote WHERE Name = '$Name'") 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=".$_SERVER['PHP_SELF']."?mode=vote&voted=1&Id=".$ratings['Id'].">Vote 1</a> | ";
Echo "<a href=".$_SERVER['PHP_SELF']."?mode=vote&voted=2&Id=".$ratings['Id'].">Vote 2</a> | ";
Echo "<a href=".$_SERVER['PHP_SELF']."?mode=vote&voted=3&Id=".$ratings['Id'].">Vote 3</a> | ";
Echo "<a href=".$_SERVER['PHP_SELF']."?mode=vote&voted=4&Id=".$ratings['Id'].">Vote 4</a> | ";
Echo "<a href=".$_SERVER['PHP_SELF']."?mode=vote&voted=5&Id=".$ratings['Id'].">Vote 5</a><p>";
}
//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>";
}

//Otherwise, we set a cooking telling us they have now voted
else
{
$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 RecipeVote SET Total = Total+$voted, Votes = Votes+1 WHERE Name = $Name");
Echo "Your vote has been cast <p>";
}
} 
mysql_close();
?>

 

im following this

http://php.about.com/od/finishedphp1/ss/rating_script.htm

Link to comment
https://forums.phpfreaks.com/topic/129921-solved-rating-script/
Share on other sites

thats it the lines before it are a completly different peice i just added the opening for the php so it would color the script properly

 

line 160 is

 

if ( $mode=="vote")  // line 160

{

 

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

}

 

//Otherwise, we set a cooking telling us they have now voted

else

{

$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 RecipeVote SET Total = Total+$voted, Votes = Votes+1 WHERE Name = $Name");

Echo "Your vote has been cast <p>";

}

}

mysql_close();

?>

Link to comment
https://forums.phpfreaks.com/topic/129921-solved-rating-script/#findComment-673527
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.