I have made dynamic links in PHP, to display individual bikes, using the bike ID in my website. This is my code that makes each link individual on my index page:
$bike_id = $bike["bike_id"];
echo '<a href="./item.php?id='.$bike_id.'"><input type="button" value="See More" />';
Now the issue I face is trying to display each bike item pages unique values. for example, if you selected "Fast bike" on index.php, you'd be taken to a page that had "fast bikes" description and price.
In the database, I have the columns:
"Bike_name", "Bike_Price", "Bike_Description
and on each the bikes item page, I want to display these values, but I don't know how to do it.
Here is what I have so far but it's not working:
<?php
require_once(__DIR__.'/includes/db.php'); //connect to the database
$item_id = $_GET['id']; //get the ID of the item
$item_data = mysql_query("SELECT bike_name"); //get the value of the column bike_name
echo "<h2>".$item_data['bike_name']."</h2>"; //display the value of the column bike_name
?>
I was advsed to do this:
// Select item from database
// Store results in $item_data
// echo $item_data[`item_name`];
My connection (I'm not showing my passwords or usernmane)
try {
$Conn = new PDO("mysql:host=".$db_config['db_host'].";dbname=".$db_config['db_name'],$db_config['db_user'],$db_config['db_pass']);
$Conn->setAttribute(PDO::ATTR_EMULATE_PREPARES, false);
$Conn->setAttribute(PDO::ATTR_PERSISTENT, true);
$Conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
}catch (PDOException $e) {
echo $e->getMessage();
exit();
}