Jump to content

Why is this happening? Urent help.


mat-tastic

Recommended Posts

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
Share on other sites

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
Share on other sites

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
Share on other sites

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
Share on other sites

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
Share on other sites

<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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.