|
Posted by nathan.fulton on 10/26/06 19:29
Hey all,
I'm having issues with a script. When loaded, it should grab data from
a database, add 1 to the visits counter and then display the count in
the form of an image. The problem is this: when the script loads,
instead of adding 1 count to the database, it ads anywhere from 2 to 4
counts to the database. I was wondring is anyone knows whats going on
or how to fix it. I have attached my code below.
Thanks!
-Nathan
<?php
[database connection here]
$url = $_GET["url"];
//get the # of hits
$q = mysql($dbname, "SELECT * FROM counter WHERE url = '$url'");
$num = mysql_num_rows($q);
if($num != "0")
{
$do = mysql_fetch_object($q);
$newcount = $do->count + 1;
mysql($dbname, "UPDATE counter SET count = '$newcount' WHERE url =
'$url'");
mysql($dbname, "INSERT INTO counter_ip VALUES(0,'$url','$ip')");
$fontsize = "5";
}
else
{
$newcount = "user not found";
//establish font size
$fontsize = "3";
}
// create a 100*30 image
$im = imagecreate(100, 30);
// white background and blue text
$bg = imagecolorallocate($im, 255, 255, 255);
$textcolor = imagecolorallocate($im, 0, 0, 255);
// write the string at the top left
imagestring($im, $fontsize, 0, 0, $newcount, $textcolor);
// output the image
header("Content-type: image/png");
imagepng($im);
?>
[Back to original message]
|