Page 1 of 1

script incrementing by 2 on mysql update...

Posted: Tue May 08, 2012 10:38 am
by visevo
I have a simple script that takes screen dimensions from jquery/ajax and posts them up to my php script to insert into a database. pretty simple.
first it checks if the dimensions exist, and if they do, the num_users field is updated by +1.

HOWEVER

when using google chrome (not firefox, ie/7/8/9), it's incrementing by 2. every time.
so my question is: is it possible to prevent this from happening twice? Maybe a mysql setting, or some fancy code?

Here's my simple script, minus the checker, etc. it just updates values.

Code: Select all

<?php
require_once('adm/inc/functions.php');
require_once('adm/inc/config.php');
sql_connect();
$width = 1280;//mysql_real_escape_string($_POST['width']);
$height = 960;//mysql_real_escape_string($_POST['height']);
$screen_width = 1200;//mysql_real_escape_string($_POST['screen_width']);
$screen_height = 716;//mysql_real_escape_string($_POST['screen_height']);

	$quer = "UPDATE `$db`.data SET `num_users` = `num_users` + 1 WHERE `id` = $id";
	if($result = mysql_query($quer)){
		echo "Updated.";
	}
	else{
		die("Error: ".mysql_error());
	}
?>
any ideas / thoughts / solutions appreciated.

Re: script incrementing by 2 on mysql update...

Posted: Tue May 08, 2012 2:39 pm
by tr0gd0rr
There is nothing that looks wrong there. Can you confirm by using Chrome Dev Tools that the ajax request is only firing once?

Re: script incrementing by 2 on mysql update...

Posted: Tue May 08, 2012 4:51 pm
by visevo
no need, for the test phase it is easier for me to just use set variables instead of post variables, so ajax wasn't running.

Another interesting twist: It only did this on my local test server, not on the live server... restarting apache & mysql seemed to fix it.