UPDATE Mysql/PHP Problem

Soldato
Joined
4 Jul 2004
Posts
2,647
Location
aberdeen
Hi
I have this code :
PHP:
mysql_connect($url,$username,$password);
@mysql_select_db($db) or die( "Unable to select database");



if (isset($_REQUEST['uid']))
{
$uidd = strip_tags($_REQUEST['uid']);
  

		
			
			  Header("Content-type: image/gif");
			  readfile('sample.gif');
				  
		
  $test = '1';
while ($test == '1') {
	mysql_query("UPDATE counter SET hits=hits+1 WHERE uid = '$uidd'");
$test = 0;}
}
The $test while bit is just a test, to see if it loops more than once, which it doesn't.
Basically, it should update hits to hits + 1 yeh? Well ... it does hits + 2.

(ie, i go to the page with the image, it should add 1 to the hits, but instead it adds 2 every time. i cant work out why)

Any ideas?
BTW it *seems* to work fine if i take out the image bits (the header/read file lines).
 
Last edited:
Thanks.
And meh who needs security when you get no visits :p
But yeh, I know. I just couldn't be bothered to either find something that lets me make sure its an md5 hash, or remove any other sql commands.

But if anyone has any ideas???
Thanks

Actually ... even this still adds 2 each time ...
PHP:
<?php

mysql_connect($url,$username,$password);
@mysql_select_db($db) or die( "Unable to select database");



if (isset($_REQUEST['uid']))
{
$uidd = mysql_real_escape_string(strip_tags($_REQUEST['uid']));
	  
				mysql_query("UPDATE counter SET hits=hits+1 WHERE uid = '$uidd'");
				
			  Header("Content-type: image/gif");
			
			  readfile('sample.gif');
				  

}



?>
 
Last edited:
Dj_Jestar said:
No, I mean when you embed it in your (X)HTML with <img src="blah.php" /> do you have two of those?

The only reason that I can see, that it is updating twice is because the script is being called/invoked twice.

Also, to clear any semantics, change your SQL query to the 'proper' (strict) syntax using backticks (`) when you are identifying tables and columns:

Code:
UPDATE `counter` SET `hits` = `hits` + 1 WHERE `uid` = '$uuid'
Ah Isee what you mean. Well no, its only in the pages once, and i'vebeen mostly testing by putting the "image" (ie the php file) in the address bar, checking it that way. I'll change the mysql query to what you posted, in a min, see if that helps.

It works fine, without the image stuff (read file/header)

Thanks
 
Back
Top Bottom