I'm real stuck on a php jump script.
Basically a value is called from my .html pages; somthing like this: <a href="jump.php?m=c"> which looks at the jump.php page and redirects the user.
I track the number of clicks in a MySql database. I want the code to check the database to see if a link already exists. If it does, I want to add 1 to the click count. If it doesn't, I want to be create a new entry. That's all.
I've tested each section of the code and each bit works. Put it toguther and for some reason, it fails and I end up with loads of duplicate entries. My if condition may be incorrect. My php / mySql knowledge isn't great as I've only just started, so please bear with me!
//Here's my code - left out the connection part.
if ($m == "a")
{$link = "[URL]http://www.web1.html[/URL]";}
if ($m == "b")
{$link = "[URL]http://www.web2.html[/URL]";}
if ($m == "c")
{$link = "[URL]http://www.web3.html[/URL]";}
// Check if the $m value exists in the db
$result = mysql_query("SELECT name FROM clicks WHERE name='$m'") or die(mysql_error());
$row = mysql_fetch_array($result);
if ($row['name'] == '$m') //Look for $m in the database and see if it exists.
{
$result = mysql_query("UPDATE clicks SET clicks=clicks WHERE name='$m'") or die(mysql_error());
}
else
{
$result = mysql_query("INSERT INTO clicks (name,links) VALUES ('$m','somelinks')") or die(mysql_error());
}
header("Location: $link"); // Jump to the hiddden affiliate URL above
exit();
?>
Any ideas, clever people!
Mork