eevan79 Posted December 15, 2009 Share Posted December 15, 2009 I want to avoid double vote using session, but cant make it to work. Here is my script: <?php $mode = $_GET[''mode'']; $voted = intval($_GET[''voted'']); //vote 1 to 5 if(($voted < 1)||($voted>5)) die; if ($mode=="vote") { //update mysql mysql_query ("UPDATE fraze SET total = total+$voted, votes = votes+1, srednja = round(total/votes, 2) WHERE id = $id"); echo "<meta http-equiv=''refresh'' content=''0;URL=http://www.mysite.info/index.php?id=".$red[''id'']."''>"; } ?> Thanks in advance. Link to comment https://forums.phpfreaks.com/topic/185238-session-avoid-double-vote/ Share on other sites More sharing options...
Kestrad Posted December 15, 2009 Share Posted December 15, 2009 if(($voted < 1)||($voted>5)) die; do you need curly braces for this line? Link to comment https://forums.phpfreaks.com/topic/185238-session-avoid-double-vote/#findComment-977869 Share on other sites More sharing options...
eevan79 Posted December 15, 2009 Author Share Posted December 15, 2009 if(($voted < 1)||($voted>5)) die; do you need curly braces for this line? I dont think so . But still I have problem with double vote. I dont know how to use session to avoid double (or multiple) vote. Link to comment https://forums.phpfreaks.com/topic/185238-session-avoid-double-vote/#findComment-977871 Share on other sites More sharing options...
Lamez Posted December 15, 2009 Share Posted December 15, 2009 Are you getting errors? If you are using sessions, I don't see anything related to sessions. You also need to remember to add session_start(); Link to comment https://forums.phpfreaks.com/topic/185238-session-avoid-double-vote/#findComment-977873 Share on other sites More sharing options...
dpacmittal Posted December 15, 2009 Share Posted December 15, 2009 <?php session_start(); if($_SESSION['voted']==1) { echo "Already voted"; exit 0; } $mode = $_GET[''mode'']; $voted = intval($_GET[''voted'']); //vote 1 to 5 if(($voted < 1)||($voted>5)) die; if ($mode=="vote") { //update mysql mysql_query ("UPDATE fraze SET total = total+$voted, votes = votes+1, srednja = round(total/votes, 2) WHERE id = $id"); $_SESSION['voted']=1; echo "<meta http-equiv=''refresh'' content=''0;URL=http://www.mysite.info/index.php?id=".$red[''id'']."''>"; } ?> Link to comment https://forums.phpfreaks.com/topic/185238-session-avoid-double-vote/#findComment-977876 Share on other sites More sharing options...
eevan79 Posted December 15, 2009 Author Share Posted December 15, 2009 Thanks, dpacmittal Solved. Link to comment https://forums.phpfreaks.com/topic/185238-session-avoid-double-vote/#findComment-977883 Share on other sites More sharing options...
dpacmittal Posted December 15, 2009 Share Posted December 15, 2009 But that will avoid double vote as long as session lasts. You'd have to store the voted info in database for avoiding double votes forever. Link to comment https://forums.phpfreaks.com/topic/185238-session-avoid-double-vote/#findComment-977890 Share on other sites More sharing options...
eevan79 Posted December 15, 2009 Author Share Posted December 15, 2009 But that will avoid double vote as long as session lasts. You'd have to store the voted info in database for avoiding double votes forever. I really like to do that, but dont know how (I already tried something, but always failed). Link to comment https://forums.phpfreaks.com/topic/185238-session-avoid-double-vote/#findComment-977894 Share on other sites More sharing options...
Lamez Posted December 15, 2009 Share Posted December 15, 2009 Then look up MySQL insert queries, and things revolving that matter. They will help a ton Link to comment https://forums.phpfreaks.com/topic/185238-session-avoid-double-vote/#findComment-977895 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.