我之前问过这个问题,但没有得到任何实际答案。我为妻子的珠宝创建了一个网站。她想为自己制作的每种款式(手链,项链等)提供一个产品页面。
我创建了一个带有类别部分的数据库,该部分具有她创建的所有不同类别。我唯一的问题是我无法获取要显示在产品页面上的信息。我收到诸如
之类的错误注意:未定义的变量:第83行的C:\ xampp \ htdocs \ pinkys_pearls \ bracelets.php中的item_number。
这是我的页面代码:
<?php
error_reporting(E_ALL);
ini_set('display_startup_errors', 1);
ini_set('display_errors', 1);
?>
<?php
// Connect to the MySQL database
include_once("storescripts/connect_to_mysql.php");
$con = mysqli_connect("$db_host","$db_username","$db_pass","$db_name");
if (mysqli_connect_errno()) {
printf("Connect failed: %s\n", mysqli_connect_errno());
exit();
//Initializing variable
$item_number = "item_number";
$description = "description";
$category = "category";
$price = "price";
$qty = "qty";
$sql = "SELECT category FROM products WHERE category='Bracelets';";
$result = mysqli_query($con, $sql);
$resultCheck = mysqli_num_rows($result);
if ($resultCheck > 0) {
// get all the product details
while($row = mysqli_fetch_assoc($result)); {
echo $item_number = $row["item_number"];
$price = $row["price"];
$desc = $row["description"];
$category = $row["category"];
}
}
else {
echo "Data to render this page is missing.";
exit();
}
}
?>
<!DOCTYPE html>
<html>
<head>
<title>Bracelets</title>
<meta charset="utf-8">
<meta http-equiv="x=UA-comparable" content="IE-edge">
<meta name="description" content="Pinky's Pearls is a website where one of a kind jewelry designed by Nichole <q>Nicki</q> can be seen and purchased">
<meta name="keywords" content="jewelry, beads, bracelets, rings, pendants, necklaces, pearls, crystal">
<meta name="viewpoint" content="width=device-width, initial-scale=1">
<meta name="author" content="samuel jaycox">
<link href="style.css" rel="stylesheet">
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css">
<link rel="shortcut icon" type="image/png" href="pictures/pinky.png">
<script src="https://use.fontawesome.com/0c9491c5b9.js"></script>
</head>
<body>
<div align="center" id="wrapper">
<div id="banner-wrapper">
<!---Company Header-->
<header>
<div id="header">
<img class="bracelet_header" src="pictures/headers/bracelets.jpg" alt="Bracelets">
<audio autoplay="autoplay" loop="loop" id="background-music">
<source src="music/Albinoni-adagio-in-g-minor-acoustic-guitar.mp3" type="audio/mpeg">
<source src="music/Albinoni-adagio-in-g-minor-acoustic-guitar.wav" type="audio/wav">
</audio>
</div>
</header>
<!---end of Company Header-->
<br>
<?php include_once("templates/template_navigation.php"); ?>
<br>
<br>
<br>
<!--Start Comment page Body Content-->
<div id="body-content">
<div class="bracelet_body">
<table width="100%" border="2" cellspacing="0" cellpadding="15">
<tr>
<td width="19%" valign="top">
<img src="pictures/inventory/<?php echo $pid; ?>.png" width="142" height="188" alt="<?php echo $item_number; ?>" /><br />
<a href="pictures/inventory/<?php echo $pid; ?>.png">View Full Size Image</a>
</td>
<td width="81%" valign="top">
<h3><?php echo $item_number; ?></h3>
<p><?php echo "$".$price; ?>
<br /><br />
<?php echo $desc; ?>
<br />
</p>
<form id="form1" name="form1" method="post" action="cart.php">
<input type="hidden" name="pid" id="pid" value="<?php echo $id; ?>" />
<input class="button" type="submit" name="button" id="button" value="Add to Shopping Cart" />
</form>
</td>
</tr>
</table>
</div>
</div>
<!--end of Comment body-->
<?php include_once("templates/template_footer.php"); ?>
</body>
</html>
该如何解决?
答案 0 :(得分:-1)
您在关键点缺少右花括号-
if (mysqli_connect_errno()) {
printf("Connect failed: %s\n", mysqli_connect_errno());
exit();
// RIGHT HERE
//Initializing variable
$item_number = "item_number";
$description = "description";
$category = "category";
没有它,不会初始化任何变量,永远不会运行SQL查询,等等。
解决此问题后,请重试,如果仍有相关问题,请编辑该问题,否则,请为新问题开始一个新问题。