require "assets/php/config.php";
error_reporting(E_ALL);
$location = null;
if(isset($_GET['l']))
{
$location = retrieveAddress($_GET['l']);
}
if($location != null){
header('Location: ' . $location);
}
else{
header('HTTP/1.0 404 Not Found');
echo 'Unknown link.';
}
public static function retrieveAddress($name)
{
$con = new PDO(Config::$host,
Config::$user,
Config::$password);
if (!$con) {
die('Could not connect: ' . mysql_error());
}
$sql = $con->prepare('SELECT address FROM links WHERE name = ?');
$sql->execute($name);
$location = $sql->fetchAll(PDO::FETCH_ASSOC);
$con = null;
return $location;
}
This script should allow me to go to my database where I save links and then redirect to that location, made it while working on a simple url shortener, I can easily add links so the database configuration works, however when I try to retrieve here nothing appears. I also tried to use error_reporting(E_ALL); but I still get nothing. Anyone got any idea, see anything wrong I fail to see?(I m sure there is something wrong but I can't notice
*Edit: I reach the file via link, no ajax is used. I removed all the text echos and I don t know how to check the value of the $location to see if I'm getting the proper value without using echo, I also edited the mysql to grab only the address, I was also getting the name, which was another mistake, but I seem to have one more somewhere.