I'm pretty new to web development and teaching myself from scratch. I'm running through a few drills to teach myself and get myself familiar with PHP and MySQL as languages and using a simple sweetshop as an example. I want to produce a page which simply lists the names of my sweets and hyperlinks to a new page which tells you more info. I've written the following code from scratch and it makes sense in my head, but there must be an error hidden in there. Would massively appreciate it if anyone could spot my mistake and/or give any tips for what to look out for in the future. Thanks!
<?php //sweetshop.php
require_once 'login.php';
$conn = new mysqli($hn, $un, $pw, $db);
if ($conn->connect_error) die("Error Sweetshop.");
$query = "SELECT * FROM products";
$result = $conn->query($query);
if (!$result) die("Fatal Error");
$rows = $result->num_rows;
for ($j = 0; $j < $rows; ++$j)
{
$row = $result->fetch_array(MYSQLI_ASSOC);
?><a href="product?product_id=<?php echo htmlspecialchars($row['product_id'])?>"><?php echo htmlspecialchars($row['sweet'])?></a><br/><?
}
$result->close();
$conn->close();
?>