View Full Version : Retrive Link from the Mysql with ID

02-24-2010, 05:23 AM

If i have a URL Saved in my Mysql table , lets Say like


and i need to Put a small Image with href when User Clicks it , Take Him to the URL but instaed Print Out the Actual link i need to mask it with the ID of the Link .. like


where 1 = http://locahost

This Example i need to Fix

mysql_connect("localhost", "root", "12") or die(mysql_error()) ;
mysql_select_db("test") or die(mysql_error()) ;

$data = mysql_query("SELECT * FROM links WHERE id='$id'") or die(mysql_error());
while($info = mysql_fetch_array( $data ))
Echo "<b>Download Link </b> <a href='getfile.php?id=$id'><img src='download.jpg' width='22' height='16'></a> ".$info['link'] . "<br> ";

02-24-2010, 06:02 AM
mysql_connect("localhost", "root", "12") or die(mysql_error());
mysql_select_db("test") or die(mysql_error());
$id = mysql_real_escape_string($_GET['id']);
$data = mysql_query("SELECT * FROM links WHERE id = '$id'") or die(mysql_error());
while($info = mysql_fetch_array($data)){
echo("<b>Download Link</b> <a href='getfile.php?id=$id'><img src='download.jpg' width='22' height='16'></a> ".$info['link'] . "<br> ");

That should work - you almost had it right, but forgot to retrieve the ID from the URI, and remember that you should secure the input.

Get the link like this: http://localhost/getfile.php?id=1

02-24-2010, 06:05 AM
Thank you .. :)