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);
?> 2 1476 na***********@gmail.com wrote:
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.
Hmmm ... I really don't like the idea that the image itself updates
the database. I'd do the updating outside the image
Where you have, in your HTML:
<img src="image.php?url=http%3A%2F%2Fwww.google.com%2F" >
I'd do this instead:
<?php log_and_count('http://www.google.com/'); ?>
<img src="image.php">
and, of course, remove the INSERT/UPDATE update stuff from the
image code, leaving only the SELECT part.
The `log_and_count()` function would do the INSERT/UPDATE stuff.
--
I (almost) never check the dodgeit address.
If you *really* need to mail me, use the address in the Reply-To
header with a message in *plain* *text* *without* *attachments*.
works great. Thank's for the reply.
On Oct 26, 6:17 pm, Pedro Graca <hex...@dodgeit.comwrote:
nathan.ful...@gmail.com wrote:
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.Hmmm ... I really don't like the idea that the image itself updates
the database. I'd do the updating outside the image
Where you have, in your HTML:
<img src="image.php?url=http%3A%2F%2Fwww.google.com%2F" >
I'd do this instead:
<?php log_and_count('http://www.google.com/');?>
<img src="image.php">
and, of course, remove the INSERT/UPDATE update stuff from the
image code, leaving only the SELECT part.
The `log_and_count()` function would do the INSERT/UPDATE stuff.
--
I (almost) never check the dodgeit address.
If you *really* need to mail me, use the address in the Reply-To
header with a message in *plain* *text* *without* *attachments*.
This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: pieter.breed |
last post by:
Hi All,
The company I work for has traditionally used COM/ActiveX for the
solutions that it provides. We are in the process of moving to .NET and
a few applications have been written in VB.NET...
|
by: K.S.Liang |
last post by:
Hi all,
1> If there are more than one dynamic linking libraries in the file
system, how do I know which one is loaded into system? Any C library
or system call can tell me which *.so or *.sl is...
|
by: Jim |
last post by:
Have fully operational software package developed on VB.NET that worked until Jan 1 2003, with early stage deployments on Oct 10, Oct 23, Nov 11, Dec 12 and Dec 30.
When attempted final...
|
by: mwt |
last post by:
So in a further attempt to learn some Python, I've taken the little
Library program
(http://groups.google.com/group/comp.lang.python/browse_thread/thread/f6a9ccf1bc136f84)
I wrote and added...
|
by: Julian |
last post by:
I get the following error when i try to link a fortran library to a c++ code
in .NET 2005.
LINK : fatal error LNK1104: cannot open file 'libc.lib'
the code was working fine when built using...
|
by: Frank-O |
last post by:
Hi ,
Recently I have been commited to the task of "translating" some complex
statistical algorithms from Matlab to C++. The goal is to be three
times as fast as matlab ( the latest) .
I've...
|
by: =?Utf-8?B?WW9naSBXYXRjaGVy?= |
last post by:
Hello,
I am using Visual Studio-2003. I created a project to build my library.
Since I am using third party libraries as well, I have specified those
additional library dependencies in project...
|
by: JosAH |
last post by:
Greetings,
the last two article parts described the design and implementation of the
text Processor which spoonfeeds paragraphs of text to the LibraryBuilder.
The latter object organizes, cleans...
|
by: JosAH |
last post by:
Greetings,
welcome back; above we discussed the peripherals of the Library class: loading
and saving such an instantiation of it, the BookMark interface and then some.
This part of the article...
|
by: Xiaoxiao |
last post by:
Hi,
I got a C library, is there a way to view the public function names in
this library so that I can use in my C program?
Thanks.
|
by: emmanuelkatto |
last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud.
Please let me know.
Thanks!
Emmanuel
|
by: BarryA |
last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers,...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new...
| |