Page 1 of 1

[SOLVED] PHP to register the link is clicked and write to DB

Posted: Tue Jun 15, 2004 1:42 pm
by Calimero
When a visitor clicks on the link I need PHP to run this sql code:

insert into col1 values ($link);

I wrote $link because for every link I need an identifier either as a number or a alphabetical description.

I have no clue how this should be done in PHP, so yes :lol: , I would need a code for this.

Thanks !!!

Posted: Tue Jun 15, 2004 1:47 pm
by Illusionist
Maybe a little more information would be helpful. If the link is to another PHP page, then just add your query in on that page.

SORRY

Posted: Tue Jun 15, 2004 1:50 pm
by Calimero
Sorry,
This I need for outgoing users - for my text-ual advertisement, just to register how many of my users have chosen this or that link

Posted: Tue Jun 15, 2004 1:51 pm
by Illusionist
Ok, that didn't help any...

OuuuuKey

Posted: Tue Jun 15, 2004 1:58 pm
by Calimero
This is the idea:
Someone clicks on the link that will take him/her outside of my site to another site.
All I need is for PHP to record this click on the link and insert it in the DB with the sql code menthioned above

Is it clear now ??

Posted: Tue Jun 15, 2004 2:02 pm
by d3ad1ysp0rk
like..

links look like this:

Code: Select all

<a href="out.php?x=3">Link #3</a>
out.php looks like this:

Code: Select all

<?php 
if(!empty($_GET['x'])){
  //connect to mysql
  $sql = "UPDATE table_name SET clicks = clicks+1 WHERE id =       {$_GET['id']}";
  mysql_query($sql);
  $sql2 = "SELECT url FROM table_name WHERE id = {$_GET['id']}";
  $url = mysql_result(mysql_query($sql2),0,0);
  header("Location: ".$url);
}
else {
  echo "Error..";
}
?>

Posted: Tue Jun 15, 2004 3:09 pm
by dull1554
yea, you need to keep in mind that for php to do anything it has to do it serverside, and the only way to do what you want to do with php would to do as Mr. lilpunkSkater said, have a inbetween page.....

Posted: Tue Jun 15, 2004 4:45 pm
by tim
or you can use Javascript to see if the banner has been selected and create the function with php to insert the data into the table

just FYI, i would go with punks route as well.