Php网页无法显示带有Wamp Server的产品列表

内容来源于 Stack Overflow,并遵循CC BY-SA 3.0许可协议进行翻译与使用

  • 回答 (1)
  • 关注 (0)
  • 查看 (40)

我正在使用php和wamp开发电子商务网站。当我点击产品超链接时,我正在尝试显示产品列表。但问题是我点击了什么链接,它显示以下错误..

错误:sqlCat

这是我的connection.php代码文件..

<?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文件的php代码。

<div class="sidebar_box"><span class="bottom"></span>
                <h3>Categories</h3>   
                <div class="content"> 
                    <ul class="sidebar_list">
                    <?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>

这是我运行应用程序时的屏幕截图..

提问于
用户回答回答于

$con可能是空的。您需要Connection.phpcategory.php页面顶部打电话。

// you have
<ul class="sidebar_list">
<?php

// you should have
<ul class="sidebar_list">
<?php
    require_once('..\db\Connection.php') ;

扫码关注云+社区

领取腾讯云代金券