...

View Full Version : Retrive Link from the Mysql with ID



ajloun
02-24-2010, 05:23 AM
Hello

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

http://locahost

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

http://localhost/getfile.php?=1

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> ";
}

iLochie
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

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



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum