0

I got the last one to work ( simple outbound link tracker - Why isn't this working? ), problems were whitespace and column name capitalization.

Now I'm trying to implement this in an existing database without any luck.

Here's the code (not including mysql connect data and obfuscating table name)

<?php 
$id = $_GET['ID'];

/** Increase the counter of the URL to which the user is going*/
mysql_query("UPDATE `table_name` SET countout = countout + 1 WHERE ID = '$id'") or die(mysql_error()); 

/** Retrieves URL */
$result = mysql_query("SELECT * FROM `table_name` WHERE ID = '$id'") or die(mysql_error()); 
$row = mysql_fetch_array($result); 

//redirects them to the link they clicked
header( "Location:" .$info['Url'] ); 
?>

And also important, here is a screenshot of the db table structure with data in it:

http://cl.ly/323A1i3L0n181P3H0J2B/Image%202012-01-05%20at%201.39.41%20PM.png

When I attempt

out.php?id=36

I get a blank page

EDIT: @Runar Jørgensen provided the fix. Just trying to secure it from SQL injection now

Community
  • 1
  • 1
elzi
  • 5,442
  • 7
  • 37
  • 61

1 Answers1

1

You have a few errors in your script that should be corrected. You should enable errors, while developing, so that you see what's not working with your script.

First of all: Variables are case-sensitive, and if your link is out.php?id=36 then you should use $_GET['id'] and not $_GET['ID'].

Secondly: You're redirecting to an unset url, as far as see. You should edit the header tag to look like this: header("Location: " . $row['Url']);

You should also be aware of SQL Injections, and read up on how to handle them.

Runar Jørgensen
  • 564
  • 3
  • 13
  • Doh. My mistake. Changed around variable names and left that part out. Thank you, those two fixed it. Now to figure out how to protect this from SQL injection. Thanks a lot :) – elzi Jan 05 '12 at 22:01
  • It's several ways to protect from SQL Injections. Here's something you can read: http://stackoverflow.com/questions/60174/best-way-to-stop-sql-injection-in-php – Runar Jørgensen Jan 05 '12 at 22:02