Page 1 of 1

Add an onclick event

Posted: Sun May 25, 2008 7:23 am
by csdavis0906
I have the line of code below running within a mysql_fetch_array loop. I want to update a table's hit count field each time link is clicked by adding an onClick event within the code below:

Code: Select all

echo '<td class="title"><a href="' . $url . '">'. $title .'</a></td><td></td>';
The update query is:

Code: Select all

$result = mysql_query("UPDATE words SET count=count+1 WHERE word='$tag'"); 
 
Any assistance would be greatly appreciated! Thanking you in advance...

Re: Add an onclick event

Posted: Sun May 25, 2008 7:42 am
by yacahuma
Do you want to just add that count or do you actually want top move to a new URL and update the count when you click??

Re: Add an onclick event

Posted: Sun May 25, 2008 7:48 am
by csdavis0906
When the user click on the title, the user is taken to the matching url and simultaneously the count should be updated. You can get a better idea of what I'm doing by visiting http://world.newsalizr.com Thanks for your response.

Re: Add an onclick event

Posted: Sun May 25, 2008 9:13 pm
by yacahuma
you can have a page like

redirect.php

Code: Select all

 
<?
$tag = $_GET['tag'];
mysql_query("UPDATE words SET count=count+1 WHERE word='$tag'"); 
header('Location: http://' . $_GET['url']);
?>
 
and have the <a href="redirect.php?tag=xxxx&url=www.whatever.com"> point to that page with the correct parameters

you should check that the request is coming from a page you know.