I am trying to pull data from the database and export it in the HTML, with the set variables. It gives me undefined variables every time. I am assuming because the data is missing? I get a good connection to the host and database, as I have run test scripts on those. Anyhow, here is the code:
Update: Thank you for the prompt responses, unfortunately still not having much luck. I returned the $id assignment, leaving that out was by accident, and I have tried with and without the while loop; I also tried to define default variables. Nothing seems to work. I keep getting "Data to render this page is missing, unless I remove that error from the code, then I get the undefined variable errors. Anyone have any final thoughts? I am brand new to SQL so it's probably something dumb that you guys are too smart to think of.
<?php if (isset($_GET['id'])) {
include "storescripts/connect_to_mysql.php"; $id = preg_replace('#[^0-9]#i', '', $_GET['id']); $sql = mysqli_query("SELECT * FROM products WHERE id='$id' LIMIT 1"); $productCount = mysqli_num_rows($sql);
if ($productCount > 0) { while($row = mysqli_fetch_array($sql)){
$product_name = $row["product_name"];
$price = $row["price"];
$details = $row["details"];
$category = $row["category"];
$subcategory = $row["subcategory"];
}
} else { echo "That item does not exist.";
exit(); } } else { echo "Data to render this page is missing."; exit(); } ?>