mat-tastic Posted September 29, 2008 Share Posted September 29, 2008 Hey Guys, I been programming php for about 3 years now. However this one has got me stumped. if (isset($_GET['vote'])) { // enter the votes and record ip etc etc $votes_query = "SELECT * FROM screenshots WHERE id = '$vote'"; $votes_result = mysql_query($votes_query, $conn_abrv) or die(mysql_error()); $id = $_GET['vote']; $addvotesql = "UPDATE screenshots SET votes = votes + 1 WHERE id = '$id'"; $addvote = mysql_query($addvotesql, $conn_abrv) or die(mysql_error()); } It keeps adding TWO to the database, instead of one. I have tried loads of different ways, I have tried getting the value of $votes, then adding one to it. I echo'ed the result of the addition, and it had the correct result, however then checked the database, and it had added two? Please help! Does anyone also know a way to effectively stop people voting twice, apart from IP bans and sessions/cookies? Link to comment https://forums.phpfreaks.com/topic/126244-why-is-this-happening-urent-help/ Share on other sites More sharing options...
waynew Posted September 29, 2008 Share Posted September 29, 2008 Em... try this; although I doubt that it will change anything. $addvotesql = "UPDATE screenshots SET votes = (votes + 1) WHERE id = '$id'"; That's a strange one. Link to comment https://forums.phpfreaks.com/topic/126244-why-is-this-happening-urent-help/#findComment-652805 Share on other sites More sharing options...
mat-tastic Posted September 29, 2008 Author Share Posted September 29, 2008 Nope, thanks anyway. It still added two. I have made sure the query isn't being performed twice, I have checked the table structure. This is so confusing. Link to comment https://forums.phpfreaks.com/topic/126244-why-is-this-happening-urent-help/#findComment-652809 Share on other sites More sharing options...
mat-tastic Posted September 29, 2008 Author Share Posted September 29, 2008 Any other ideas? This is weird. Link to comment https://forums.phpfreaks.com/topic/126244-why-is-this-happening-urent-help/#findComment-652837 Share on other sites More sharing options...
DamienRoche Posted September 29, 2008 Share Posted September 29, 2008 Maybe try to separate the calculation. Retrieve the previous number, add 1 and reinsert. $num = $fetch['votes'] +1; ///of course, $fetch will have to be created then.. SET votes = $num WHERE..etc not ideal, but should work. Very strange. Link to comment https://forums.phpfreaks.com/topic/126244-why-is-this-happening-urent-help/#findComment-652842 Share on other sites More sharing options...
mat-tastic Posted September 29, 2008 Author Share Posted September 29, 2008 I tried that earlier, I just tried it again, it went from 10 to 12. This so weird. Link to comment https://forums.phpfreaks.com/topic/126244-why-is-this-happening-urent-help/#findComment-652856 Share on other sites More sharing options...
mat-tastic Posted September 29, 2008 Author Share Posted September 29, 2008 UPDATE: I just did a test, I made it remove one number from the total number of votes, and it only took one off. SO it appears that its just adding. If I add one it always adds two. Link to comment https://forums.phpfreaks.com/topic/126244-why-is-this-happening-urent-help/#findComment-652859 Share on other sites More sharing options...
redarrow Posted September 29, 2008 Share Posted September 29, 2008 you havent got the database set up correctly i guess change the field to a INT i bet your incrementing on the database side off things lol....... Link to comment https://forums.phpfreaks.com/topic/126244-why-is-this-happening-urent-help/#findComment-652904 Share on other sites More sharing options...
PFMaBiSmAd Posted September 29, 2008 Share Posted September 29, 2008 Your browser is requesting the page twice. This is either due to the browser (FF will request a page twice if the page does not have any character encoding specified and FF is applying its' default encoding), you have some javascript that is submitting the form and the form is being submitted by the browser as well, or you are using url rewriting and there is a problem with a trailing slash (I don't recall if a missing slash or an extra slash is at fault.) Link to comment https://forums.phpfreaks.com/topic/126244-why-is-this-happening-urent-help/#findComment-652905 Share on other sites More sharing options...
mat-tastic Posted September 29, 2008 Author Share Posted September 29, 2008 Your browser is requesting the page twice. This is either due to the browser (FF will request a page twice if the page does not have any character encoding specified and FF is applying its' default encoding), you have some javascript that is submitting the form and the form is being submitted by the browser as well, or you are using url rewriting and there is a problem with a trailing slash (I don't recall if a missing slash or an extra slash is at fault.) Ahh, you got it, I just tried in IE, and it is fine. So how do I fix this firefox issue? Thank you so much. Any further help on the firefox issue would be great. I am used to IE messing about, not firefox. Link to comment https://forums.phpfreaks.com/topic/126244-why-is-this-happening-urent-help/#findComment-652954 Share on other sites More sharing options...
mat-tastic Posted September 29, 2008 Author Share Posted September 29, 2008 Not sure where to start. It must be the firefox encoding issue? Not sure how to fix that. Link to comment https://forums.phpfreaks.com/topic/126244-why-is-this-happening-urent-help/#findComment-653067 Share on other sites More sharing options...
PFMaBiSmAd Posted September 29, 2008 Share Posted September 29, 2008 Make your page a valid HTML document with a doctype and a specific character encoding so that FF won't reload the page in order to apply its' own default character encoding. Here is the thread where I learned that FF does this - http://www.phpfreaks.com/forums/index.php/topic,216715.msg992061.html#msg992061 Link to comment https://forums.phpfreaks.com/topic/126244-why-is-this-happening-urent-help/#findComment-653144 Share on other sites More sharing options...
mat-tastic Posted September 29, 2008 Author Share Posted September 29, 2008 <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> I have set that and done a doctype. It still happens. However when I manually change the encoding in firefox > view > character encoding, it reloads the page once. And just adds one to the database like it should do. This is well annoying. It is definitely the page reloading, Live HTTP Headers confirms it. Link to comment https://forums.phpfreaks.com/topic/126244-why-is-this-happening-urent-help/#findComment-653240 Share on other sites More sharing options...
PFMaBiSmAd Posted September 29, 2008 Share Posted September 29, 2008 Here is a universal fix - Use sessions and set a session variable that says that the form processing code has been executed once. Check your session variable on each page request and if it is already set, skip over the form processing code. Link to comment https://forums.phpfreaks.com/topic/126244-why-is-this-happening-urent-help/#findComment-653270 Share on other sites More sharing options...
mat-tastic Posted September 30, 2008 Author Share Posted September 30, 2008 Thanks, I will do that. Link to comment https://forums.phpfreaks.com/topic/126244-why-is-this-happening-urent-help/#findComment-653525 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.