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

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
Calimero
Forum Contributor
Posts: 310
Joined: Thu Jan 22, 2004 6:54 pm
Location: Milky Way

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

Post 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 !!!
Last edited by Calimero on Tue Jun 15, 2004 5:29 pm, edited 1 time in total.
Illusionist
Forum Regular
Posts: 903
Joined: Mon Jan 12, 2004 9:32 pm

Post 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.
User avatar
Calimero
Forum Contributor
Posts: 310
Joined: Thu Jan 22, 2004 6:54 pm
Location: Milky Way

SORRY

Post 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
Illusionist
Forum Regular
Posts: 903
Joined: Mon Jan 12, 2004 9:32 pm

Post by Illusionist »

Ok, that didn't help any...
User avatar
Calimero
Forum Contributor
Posts: 310
Joined: Thu Jan 22, 2004 6:54 pm
Location: Milky Way

OuuuuKey

Post 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 ??
d3ad1ysp0rk
Forum Donator
Posts: 1661
Joined: Mon Oct 20, 2003 8:31 pm
Location: Maine, USA

Post 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..";
}
?>
Last edited by d3ad1ysp0rk on Tue Jun 15, 2004 3:38 pm, edited 2 times in total.
User avatar
dull1554
Forum Regular
Posts: 680
Joined: Sat Nov 22, 2003 11:26 am
Location: 42:21:35.359N, 76:02:20.688W

Post 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.....
User avatar
tim
DevNet Resident
Posts: 1165
Joined: Thu Feb 12, 2004 7:19 pm
Location: ohio

Post 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.
Post Reply