script incrementing by 2 on mysql update...

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
visevo
Forum Newbie
Posts: 2
Joined: Tue May 08, 2012 10:28 am

script incrementing by 2 on mysql update...

Post 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.
User avatar
tr0gd0rr
Forum Contributor
Posts: 305
Joined: Thu May 11, 2006 8:58 pm
Location: Utah, USA

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

Post 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?
visevo
Forum Newbie
Posts: 2
Joined: Tue May 08, 2012 10:28 am

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

Post 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.
Post Reply