mikeromero Posted July 15, 2010 Share Posted July 15, 2010 hey so im just trying to figure out how to get a rating system working so that i can put it in my site...but im having some problems getting it to work... for some reason it just wont submit the data when i press any of the buttons to vote :/ i think the problem is that im just not defining the "mode" variable the right way, because when i put "echo $mode", it doesnt do anythin. it just appears blank. so anyways, heres the code ive got. hopefully someone can tell me what im doing wrong! <?php mysql_connect("localhost", "user", "pass")or die(mysql_error()); mysql_select_db("rating") or die(mysql_error()); Echo $mode; if($mode==vote){ mysql_query ("UPDATE vote SET total = total+$voted, votes = votes+1 WHERE id = $id"); Echo "Your vote has been cast <p>"; } $data = mysql_query("SELECT * FROM vote") or die(mysql_error()); while($ratings = mysql_fetch_array( $data )) { Echo "Name: " .$ratings['name']."<br>"; $current = $ratings[total] / $ratings[votes]; Echo "Current Rating: " . round($current, 1) . "<br>"; 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>Vote 5</a><p>"; } ?> -thanks mike Link to comment https://forums.phpfreaks.com/topic/207781-help-with-a-rating-system/ Share on other sites More sharing options...
Pikachu2000 Posted July 15, 2010 Share Posted July 15, 2010 If mode doesn't equal 'vote' when you echo it, that code won't insert anything. Therefore, please post the code relevant to where $mode is assigned a value. Link to comment https://forums.phpfreaks.com/topic/207781-help-with-a-rating-system/#findComment-1086189 Share on other sites More sharing options...
mikeromero Posted July 15, 2010 Author Share Posted July 15, 2010 Echo "<a href=".$_SERVER['PHP_SELF']."?mode=vote&voted=4&id=".$ratings[id].">Vote 4</a> | "; doesnt that assign $mode to "vote" and also $voted to 4 when you click that link? or is that what im doing wrong maybe? ...sorry im kinda a newb at this Link to comment https://forums.phpfreaks.com/topic/207781-help-with-a-rating-system/#findComment-1086193 Share on other sites More sharing options...
Pikachu2000 Posted July 15, 2010 Share Posted July 15, 2010 It assigns it to $_GET['mode']. You'll need to either do if($_GET['mode']==vote){ OR $mode = $_GET['vote']; if($mode==vote){ Link to comment https://forums.phpfreaks.com/topic/207781-help-with-a-rating-system/#findComment-1086197 Share on other sites More sharing options...
mikeromero Posted July 15, 2010 Author Share Posted July 15, 2010 hey thanks that worked! thanks a bunch! Link to comment https://forums.phpfreaks.com/topic/207781-help-with-a-rating-system/#findComment-1086223 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.