我正在使用wamp和mysql数据库开发电子商务系统。我想显示数据库中的记录列表(产品)。但是问题是当我在localhost
中运行应用程序时,它在category.php
文件中抛出此错误消息(“ Error in:sqlCat”); 。我想知道可能是因为在localhost
中加载网页时连接丢失了。我的connection.php
文件和category.php
文件存在两个不同的文件夹...
这是我的connection.php
文件。这是此文件的目录。 C:\wamp64\www\onlineordering\db
<?php
$servername = "localhost";
$username = "root";
$password = "";
$db = "ecom1";
// Create connection
$con = mysqli_connect($servername, $username, $password,$db);
// Check connection
if (!$con) {
die("Connection failed: " . mysqli_connect_error());
}
?>
这是category.php
文件。这是此文件的目录。 C:\wamp64\www\onlineordering\include
<div class="sidebar_box"><span class="bottom"></span>
<h3>Categories</h3>
<div class="content">
<ul class="sidebar_list">
<?php
require_once('../onlineordering/db/connection.php') ;
$sqlCat= "select * from category where recordstatus='' order by sequence_order Asc";
$exeCat = mysqli_query($con,$sqlCat) or die ("Error in:sqlCat");
$counCat= mysqli_num_rows($exeCat);
if($counCat>0)
{
$classCat=1;
while($resCat= mysqli_fetch_array($exeCat))
{
$categoryname= $resCat["categoryname"];
$auto_number= $resCat["auto_number"];
?>
<form method="post" style="margin:0px;padding:0px;" action="productcategory.php" id="frmdetailcat<?php echo $classCat;?>">
<input type="hidden" name="category" value="<?php echo $categoryname?>">
<input type="hidden" name="categoryid" value="<?php echo $auto_number?>">
</form>
<?php
if($classCat==1)
{
?>
<li class="first"><a style="cursor:pointer;" onclick="subform('frmdetailcat<?php echo $classCat;?>')" ><?php echo $categoryname;?></a></li>
<?php
}else
if($classCat==$counCat)
{
?>
<li class="last"><a style="cursor:pointer;" onclick="subform('frmdetailcat<?php echo $classCat;?>')" >
<?php echo $categoryname;?></a></li>
<?php
}else
{
?>
<li><a style="cursor:pointer;" onclick="subform('frmdetailcat<?php echo $classCat;?>')" >
<?php echo $categoryname;?></a></li>
<?php
}
$classCat++;
}
}else
{
?>
<li class="first"><a href="#">No Category is avaliable</a></li>
<?php
}
?>
</ul>
</div>
</div>
答案 0 :(得分:2)
如果您知道导致mysqli_query()
死亡的原因而不是抛出自定义错误消息,则更容易解决:
$exeCat = @mysqli_query($con, $sqlCat);
if($exeCat){ //It worked!
//Your code
}else{ // It didn't work
// Message for you (for debugging purposes but never show this message to public)
echo '<p>' . mysqli_error($con) . '</p>';
}
您为什么在这里使用这些星号?
$exeCat = mysqli_query($con,$sqlCat) **or die ("Error in:sqlCat");**//Always display this message
删除星号:
$exeCat = mysqli_query($con,$sqlCat) or die ("Error in:sqlCat");//Always display this message
mysqli_num_rows()
有一个参数,所以这一行
$counCat= mysqli_num_rows($con,$exeCat);
也应该是
$counCat= mysqli_num_rows($exeCat);
正斜杠用作目录分隔符有什么问题?