I am creating an e-commerce website and making an ordering system however, with my code shown below, I get the error "data to render this page is missing". I have tried various work arounds but do not seam to get any further with this.
Could you please see if I am missing anything out or if there is a solution to this question?
At this stage I am trying to display my products from the sql database
Thank You for the help
<?php
// Script Error Reporting
error_reporting(E_ALL);
ini_set('display_errors', '1');
?>
<?php
// Check to see the URL variable is set and that it exists in the database
if (isset($_GET['clothing_name'])) {
// Connect to the MySQL database
include "/xampp/htdocs/website/connection.php";
$sql = mysql_query("SELECT * FROM items WHERE clothing_name='$clothing_name' LIMIT 1");
$productCount = mysql_num_rows($sql); // count the output amount
if ($productCount > 0) {
// get all the clothing details
while($row = mysql_fetch_array($sql)){
$clothing_name = $row["clothing_name"];
$size = $row["size"];
$price = $row["price"];
$details = $row["details"];
}
} else {
echo "That item does not exist.";
exit();
}
} else {
echo "Data to render this page is missing.";
exit();
}
mysql_close();
?>
Add this to your code:
$clothing_name = $_GET['clothing_name'];
Update:
<?php
// Script Error Reporting
error_reporting(E_ALL);
ini_set('display_errors', '1');
// Check to see the URL variable is set and that it exists in the database
if (isset($_GET['clothing_name'])) {
// Connect to the MySQL database
include "/xampp/htdocs/website/connection.php";
$clothing_name = $_GET['clothing_name']; //HERE
$sql = mysql_query("SELECT * FROM items WHERE clothing_name='".$clothing_name."' LIMIT 1");
$productCount = mysql_num_rows($sql); // count the output amount
if ($productCount > 0) {
// get all the clothing details
while($row = mysql_fetch_array($sql)){
$clothing_name = $row["clothing_name"];
$size = $row["size"];
$price = $row["price"];
$details = $row["details"];
}
} else {
echo "That item does not exist.";
exit();
}
} else {
echo "Data to render this page is missing.";
exit();
}
mysql_close();
?>
First of all you need to pass a QueryString against which there are any records in your database. $_GET[clothing_name]
will be set only if you provide it in your QueryString, since you are testing if $_GET[clothing_name]
is set by method isset()
so if you do not provide it in querystring condition will be false and you'll fall down to else condition.
Secondly define variable $clothing_name
as you used it in your query before executing your SQLQuery.
$clothing_name = $_GET['clothing_name'];
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.