473,545 Members | 2,019 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Update a counter when a link is clicked

Hello

I have seen some tutorials to put a update a counter field in a record. I
have the counter field in a table that also has a field for a path to file.

I display the records in a table on a web page e.g.

IndexNo ............Tit le............. ............... .... Link
............... ............... ...... Count
......1........ .....MyFileName ........www.mysite/files/MyFileName.doc........
......0
etc

User can click on the Link field in the table to download the file.

The problem is I can't find a way that will run an update query along the
lines of

$Query = mysql_query("UP DATE Resources SET Count = Count + 1 WHERE IndexNo
= '$IndexNo');

when the user clicks the link

Can anyone suggest a way or direct me to a tutorial

Thanks
Ian

Apr 26 '06 #1
4 3000
Ian Davies wrote:
Hello

I have seen some tutorials to put a update a counter field in a record. I
have the counter field in a table that also has a field for a path to
file.

I display the records in a table on a web page e.g.

IndexNo ............Tit le............. ............... .... Link
............... ............... ..... Count
......1........ .....MyFileName ........www.mysite/files/MyFileName.doc........ .....0
etc

User can click on the Link field in the table to download the file.

The problem is I can't find a way that will run an update query along the
lines of

$Query = mysql_query("UP DATE Resources SET Count = Count + 1 WHERE
IndexNo
= '$IndexNo');

when the user clicks the link

Can anyone suggest a way or direct me to a tutorial

Thanks
Ian


Hi,

Your question is very clear, but if I understand right, this may help:

1) Make a link to a increasecounter .php and add the filename:
<a href="increasec ounter.php?file name=MyFileName .doc">

2) In increasecounter .php:
$filename = $_GET["filename"];
// do your update in the db here

3) Redirect to the file
header("Locatio n: MyFileName.doc" );
exit;

Regards,
Erwin Moller

Apr 27 '06 #2
Thanks for your advice
Your code was just what I was looking for
It is updating the table with the counter but it is not bringing up the file
to download any more

The modified code is as follows

<a href="increasec ounter.php?file name=<?php echo $Link; ?>"

The $Link returns the full path to the file (from the same table as the
count field)

In my increase counter.php I have

*************** *************** *********
$filename = $_GET["filename"];
echo $filename;
$Query = mysql_query("UP DATE Resources SET count = count + 1 WHERE Link =
'$filename'");
header("Locatio n: $filename");
exit;
*************** *************** *********
I put the echo in just to check the file name is correct
which it is as it is used in the SQLs WHERE clause and it updates the record
as I mentioned earlier
But the file to download is not appearing. Can you see what is wrong
The address in the browser window is as follows if it helps
http://www.mysite.co.uk/increasecoun...ers/MyFile.doc

which appears to be wrong
when the file was downloading previously the address would have been

http://www.mysite.co.uk/Resources/Others/MyFile.doc

Any clues
Thanks
Ian

"Erwin Moller"
<si************ *************** *************** @spamyourself.c om> wrote in
message news:44******** *************** @news.xs4all.nl ...
Ian Davies wrote:
Hello

I have seen some tutorials to put a update a counter field in a record. I have the counter field in a table that also has a field for a path to
file.

I display the records in a table on a web page e.g.

IndexNo ............Tit le............. ............... .... Link
............... ............... ..... Count

......1........ .....MyFileName ........www.mysite/files/MyFileName.doc........
.....0
etc

User can click on the Link field in the table to download the file.

The problem is I can't find a way that will run an update query along the lines of

$Query = mysql_query("UP DATE Resources SET Count = Count + 1 WHERE
IndexNo
= '$IndexNo');

when the user clicks the link

Can anyone suggest a way or direct me to a tutorial

Thanks
Ian


Hi,

Your question is very clear, but if I understand right, this may help:

1) Make a link to a increasecounter .php and add the filename:
<a href="increasec ounter.php?file name=MyFileName .doc">

2) In increasecounter .php:
$filename = $_GET["filename"];
// do your update in the db here

3) Redirect to the file
header("Locatio n: MyFileName.doc" );
exit;

Regards,
Erwin Moller

Apr 27 '06 #3
You cannot have anything printed before header(). Remove echo filename;
and try running the script.

Hope this helps.

Thanks and God Bless!!

Ehsan
http://ehsan.bdwebwork.com

Apr 28 '06 #4
Ehsan

That was the problem
Thanks

Ian
"Ehsan" <ha*********@gm ail.com> wrote in message
news:11******** *************@i 39g2000cwa.goog legroups.com...
You cannot have anything printed before header(). Remove echo filename;
and try running the script.

Hope this helps.

Thanks and God Bless!!

Ehsan
http://ehsan.bdwebwork.com

Apr 28 '06 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
3361
by: Paul Eden | last post by:
Hello all. I'm totally stumped. Please de-stump me! I've read my data in from the database, changed it according to what i want to do and now I want to write it back. But it seems I can only use the update statement will only accept explicit fieldnames and value. The fieldnames I can live with, I only have 5 columns in the database, but...
2
2180
by: phoenix | last post by:
Hi, I wonder if the following is even possible : Suppose I have a page with a set of hyperlinks on it. Each time a hyperlink is clicked a new window is opened. What i basically want is the following : I want a counter at the client side which increments each time the user clicks one of those links. At the bottom of the page I'll put a...
8
5242
by: William Starr Moake | last post by:
I'm trying to script a download counter that will display the total number on the download page without server-side scripting. Below is my very incomplete beginning. It returns no errors, but does nothing: <script language="JavaScript"> function addClicks() { total = "form1.value"; form1.value = (eval(total.value) + (1));
1
9677
by: John Doe | last post by:
I have a PHP page that generates a list box with several options in it. I would like to have a "view" link next to the list box. When the user changes the contents of the list box, I would like the view link to update to point to the image representing that selection. So for example, if the list box held names of images I would want the...
0
2489
by: andrew | last post by:
Scenario description - We have two Oracle DB's A & B. Both DB's have a table test1 (customerid varchar2(50, val number). The idea is that for every customer id, the counter (stored in val) increases. Whenever we send a file to the customer, we tag/identify it with a counter value. This is for verification on the customer side that they have...
2
3600
by: Joseph Markovich | last post by:
I'm having some trouble with VB in Access 2000. I have a form that the user enters in just one number (in this case, it's a base salary) and then the program is going to do a bunch of math (which is not all shown) and populate a table with these new, calculated salary values. I know I shouldn't be storing calculated values in the table, but I...
4
5847
by: FangQ | last post by:
hi I am very new to mysql. I have a question about using the "on duplicate update" clause with insert command. my table "data" has two columns, field1 and field2, where field1 is the index and is "unique". when I run
1
1615
by: sank06 | last post by:
let me tell u what the code deos: retrieve data ( text box, 2 radio buttons, ) from db. on selection of any of the radio buttons, the counter should be incremented accordinglt in the database i have these fields, question, option1,option2,option1_ctr,option2_ctr. if option1 is clicked, then option1_ctr should be incremented. similarly if...
1
2212
by: Chris | last post by:
I have a snippet of a function below I fire up in the body tag of my webpage to show a hidden layer and do some stuff when any link with the name "showlink" is clicked. In the displayed layer there is some html and more javascript. How would I update the value of "str" with "node_id" each time a link is clicked? I can't figure it out... ...
0
7468
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7401
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
7656
Oralloy
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
0
7757
tracyyun
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
0
5972
agi2029
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
0
4945
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3443
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
1884
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
1014
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.