Page 1 of 1

Redirecting after count? ( PHP & DB Type Question)

Posted: Wed Mar 10, 2004 9:59 pm
by Dale
OK, im doing a link tracker script for myself that counts how every many times someone clicks on a link (clinks.php?id=2). I know how to get the number in the database to increase "1" everytime this happends, but what i want to know is how do i get it to actually goto that site?

Example:
Database Entry:
ID: 1
Site URL: http://www.d-frame.co.uk
Count: 0

When a link is clicked (example: clicks.php?id=1) it goes to http://www.d-frame.co.uk, but i only know how to do that with a frame type thing, because i have the top frame window holding the count script and the bottom table window as the table that actually views the site. So what i want to know is how do i get it so when i click the link it sends them to the site that they clicked for but still it counts it in the database without any frames being involved?

Here is an example of the code i have:
index.php

Code: Select all

<a href="./clicks.php?id=1" target="_blank">D-Frame</a>
clicks.php

Code: Select all

<?
mysql_pconnect("localhost","dale","*****") or die(mysql_error());
mysql_select_db("dale1") or die(mysql_error()); 

$query = "SELECT * FROM site_links WHERE id=".$_GET['id'].""; 
$result = mysql_query($query) or die(mysql_error()); 

while($r=mysql_fetch_array($result)) 
{ 	
	$siteurl=$r["siteurl"];
	echo "<html>

<head>
    <title>Going Away</title>
</head>

<frameset rows="90,*" framespacing="0" border="0" frameborder="0" frameborder="no" border="0">
<frame src="count.php" name="menu" scrolling="no" NORESIZE frameborder="0" marginwidth="0" marginheight="0" border="no">
<frame src="$siteurl" name="main" scrolling="auto" NORESIZE frameborder="0" marginwidth="0" marginheight="0" border="no">
</frameset>

</html>";
}
?>
count.php

Code: Select all

<?
mysql_pconnect("localhost","dale","*****") or die(mysql_error());
mysql_select_db("dale1") or die(mysql_error()); 

$query = "UPDATE site_links SET count=count+1 WHERE id=".$_GET['id']."";
$result = mysql_query($query) or die(mysql_error());
?>
I hope you followed... my english is poor, considering i was born english and have been in england for the whole of my 16 and a half-ish years...

(PS; Sorry if in wrong room!)

Posted: Wed Mar 10, 2004 10:02 pm
by markl999
Something like ..

Code: Select all

$query = "SELECT * FROM site_links WHERE id=".$_GET['id'].""; 
$result = mysql_query($query) or die(mysql_error());
$row = mysql_fetch_assoc($result);
header("Location: ".$row['site_url']);
exit;
?

Posted: Wed Mar 10, 2004 10:19 pm
by Dale
3 mins and you replied! OMG.. markl999... your like.. the brains of PHP and MySQL!!

.. and it worked! Thank you so very very very much markl999 ;)

Posted: Wed Mar 10, 2004 10:50 pm
by Dale
ok now thats the out counts how about the people coming in?

I tried this but i got an error with the syntax.

in.php

Code: Select all

<? 
mysql_pconnect("localhost","dale","***") or die(mysql_error()); 
mysql_select_db("dale1") or die(mysql_error()); 

$query = "UPDATE site_links SET in=in+1 WHERE id=".$_GET['id'].""; 
$result = mysql_query($query) or die(mysql_error()); 

header("Location: http://www.d-frame.co.uk"); 
exit;
?>
And for that im using: in.php?id=1

I get this following error:
You have an error in your SQL syntax. Check the manual that corresponds to your MySQL server version for the right syntax to use near 'in=in+1 WHERE id=1' at line 1

Posted: Wed Mar 10, 2004 10:53 pm
by markl999
'IN' is a mysql reserved word, you could backquote it, like `in` but it's probably better just to rename the 'in' column.

Posted: Wed Mar 10, 2004 11:09 pm
by Dale
oh.. heh.. you learn something new every day :D

.. and it works ;) thx again markl9999 ;)