Ender22 Posted October 14, 2007 Share Posted October 14, 2007 ??? I have one of those problems where my code works perfectly on my localhost, however when I upload it to my webhoster something very strange and unexplainable happens. Its quite the mystery that has been racking my brain all day. Heres whats going on. My Code: if($canvote) { $rating = $row_Recordset1['EpicPoints']; $rating+=$vote; $t = "UPDATE epiclink SET EpicPoints = $rating WHERE ID=$colname_Recordset1"; mysql_query($t, $EpicDatabase) or die('Error, query failed'); } Now on my localhost this code grabs the entry's current Epic Points in $rating, ads in the value for $vote and updates properly. On my webhost it does the same except it adds double the points Now obviously my first guess was that this code is getting executed twice. This doesnt seem to be the case as I added an alert("going here") and tested it out. The alert was only ever called once. Another possibility is that $rating is getting calculated improperly before the update is being called. But I did an alert($rating) and verified that the value is correct. Some additional info. To vote, users click an image on the page, which refreshes the page and passes in ?Vote=5 to the url. My php grabs this variable checks if the user can vote, and if they can the above is executed. One I click the link once I dont do anything! (to make sure im not causing something else to happen) and I check my database, and indeed double the points are added instantly. Now normally this would probably be a stupid logic mistake somewhere on my part, but I want to repeat that this works perfectly on localhost, only when uploaded to the webhost it messes up. As far as I know the only difference should be various PHP settings and stuff like that which my webhost uses. Any ideas on what could be causing this? If you can figure it out in my mind you will be an official PHP genius. Quote Link to comment https://forums.phpfreaks.com/topic/73251-a-very-tricky-mystery/ Share on other sites More sharing options...
Barand Posted October 15, 2007 Share Posted October 15, 2007 Instead of - getting the current rating, - adding votes to it, - updating with new value you could just $votes = $_GET['Vote']; mysql_query ("UPDATE epiclink SET EpicPoints = EpicPoints + $votes WHERE ID=$whatever"); Quote Link to comment https://forums.phpfreaks.com/topic/73251-a-very-tricky-mystery/#findComment-369558 Share on other sites More sharing options...
Ender22 Posted October 15, 2007 Author Share Posted October 15, 2007 Thanks for that method, however the same issue still occurs. Its still working fine locally but double the votes are being counted when the site is running on the net. any other ideas? Quote Link to comment https://forums.phpfreaks.com/topic/73251-a-very-tricky-mystery/#findComment-369580 Share on other sites More sharing options...
Barand Posted October 15, 2007 Share Posted October 15, 2007 Are you sure the update is at fault, or could there be an error when you output the votes? Quote Link to comment https://forums.phpfreaks.com/topic/73251-a-very-tricky-mystery/#findComment-369584 Share on other sites More sharing options...
Ender22 Posted October 15, 2007 Author Share Posted October 15, 2007 Yep I checked the values in PHP my admin and it shows that the output is correct. This might help: I tried updating it like this by dividing the amount of points given once: UPDATE epiclink SET EpicPoints = EpicPoints + ($votes/2) WHERE ID=$whatever When I did this and I inputted a vote of 3 it gave me 2 points. So it took 3/2=1 + 3/2=1. Therefore it appears the update is being done twice, however that shouldnt be possible as I said above, I outputted an Alert, and the alert only gets called once. Quote Link to comment https://forums.phpfreaks.com/topic/73251-a-very-tricky-mystery/#findComment-369586 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.