Make a database connection, but do not use the old mysql_connect. Try using PDO if you make your steps into this world.
// PDO as you can find on php.net
$dsn = 'mysql:dbname=testdb;host=127.0.0.1';
$user = 'dbuser'; // your database username
$password = 'dbpass'; // your database password
// note: do not use root, but create a separate user for the database.
try {
$dbh = new PDO($dsn, $user, $password);
} catch (PDOException $e) {
echo 'Connection failed: ' . $e->getMessage();
}
//this depends on the data in your database.
$sql = "SELECT url_column FROM table_name WHERE id_column = id;"
$sth = $dbh -> prepare($sql);
$sth -> execute();
$sth -> fetchAll(PDO::FETCH_OBJ);
$products_url = $sth[0]->url_column;
The data should be fetched before your page renders the $product_url
.
Edit: (extending explanation on pdo with resources)
PDO is the latest standard of handling database interaction. Provided it is configured correctly in the queries with prepared statements, PDO is safe to use and provides protection against injection. While you are making a simple single query, you can see that I do use a prepared statement.
One important rule is that you assign a designated user and password for your database. It is not safe to use root as username. Here is a resource that may help you with creating a user for the database in case you need explanation.
The best thing you can do is to familiarize yourself with PDO. You can get a good explanation from a series from phpacademy about PDO, which is well worth following and well invested time.