Rating script problem
5 star rating script I have is made based on this tutorial http://php.about.com/od/finishedphp1/ss/rating_script.htm I have changed it a bit based on comments on the mentioned site,but script still has some is开发者_C百科sues. When i rate something script refreshes the site and adds the needed parameters in query string but the rest of the script is not triggered by it.
Echo "Rate ";
Echo "<a href=".$_SERVER['PHP_SELF'].'?'.$_SERVER['QUERY_STRING']."?mode=vote&voted=1&id=".$data[id].">1</a> | ";
Echo "<a href=".$_SERVER['PHP_SELF'].'?'.$_SERVER['QUERY_STRING']."?mode=vote&voted=2&id=".$data[id].">2</a> | ";
Echo "<a href=".$_SERVER['PHP_SELF'].'?'.$_SERVER['QUERY_STRING']."?mode=vote&voted=3&id=".$data[id].">3</a> | ";
Echo "<a href=".$_SERVER['PHP_SELF'].'?'.$_SERVER['QUERY_STRING']."?mode=vote&voted=4&id=".$data[id].">4</a> | ";
Echo "<a href=".$_SERVER['PHP_SELF'].'?'.$_SERVER['QUERY_STRING']."?mode=vote&voted=5&id=".$data[id].">5</a>";
this thing is pretty much skipped.
$mode = $_GET['mode'];
$voted = $_GET['voted'];
$id = $_GET['id'];
if ($mode=='vote')
{
if(isset($_COOKIE['146829gigapuding']))
{
Echo "Sorry You have already ranked that site";
}
else
{
$month = 2592000 + time();
setcookie('146829gigapuding',Voted,$month);
mysql_query ("UPDATE searchengine SET rating = rating+$voted, votes = votes+1 WHERE id = $id");
Echo "Your vote has been cast";
}
}
The sql connection,query and bunch of other code is there but there were no problems with it,i tried moving the code order but nothing.
Another thing that worries me is there a way to remove the ?mode=vote... parameters afther vote is cast.
tnx in advance.
As I see here
".$_SERVER['PHP_SELF'].'?'.$_SERVER['QUERY_STRING']."?mode=vote&voted=1&id=".$data[id]."
you have ? (question mark) twice, which makes your url invalid. Try changing it to
".$_SERVER['PHP_SELF'].'?'.$_SERVER['QUERY_STRING']."&mode=vote&voted=1&id=".$data[id]."
and see what will happen :)
p.s.: the change is ? to & before mode
精彩评论