I working with PHP for the first time. I got some items loaded on my page and when I click on it I want to show more information. This is my connection database code:
<?php
$servername = "localhost:3306";
$username = "root";
$password = "root";
$dbname = "webshop";
// Create connection
$conn = new mysqli($servername, $username, $password, $dbname);
// Check connection
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
$sql = "SELECT * FROM items";
$result = $conn->query($sql);
$conn->close();
?>
The tables in the database are:
Id, name, prijs, cat
The connection is working fine and I can retrieve the items with the following code:
if($selected_val == "Vrouwen"){
echo'<section class="products">';
if ($result->num_rows > 0) {
while($row = $result->fetch_assoc()) {
if ($row['cat'] == 'vrouwen') {
$catvrouwen = $row['cat'];
echo "<div class='product-card'><button id='myBtn'><div class='product-image'><a href='index.php?id=" . $row['id'] . " '><img src='image/1.jpg'></a></div><h5>" . $row['name'] . '</h5><h6>' . '€' . $row['prijs'] . "</h6></button></div>";
}
$id = $row['id'];
$img = $row['img'];
$name = $row['name'];
$prijs = $row['prijs'];
echo $_POST['name'];
}
$result->close();
}
echo'</section>';
}
}
This code is working fine and when I click on the item I want to see more information about it. This is the code I wrote:
if ($id = $_GET['id']) {
echo $id;
echo '<div class="info2"><div class="info-view">';
echo "<button id='myBtn'><div class='product-image'><a href=''><img src='image/1.jpg'></a></div><h5>";
echo $name;
echo "</h5><h6>€";
echo $prijs;
echo "</h6></button></div>";
echo '</div></div>';
}
I can see only $id but $prijs and $name is not showing. Can someone help me to show this attributes? Kind regards