PHP Web应用程序始终显示错误消息

时间:2018-07-06 00:39:35

标签: php mysql wamp

我正在使用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>

这是我运行应用程序时的屏幕截图。或死掉(“ Error in:sqlCat”); //始终显示此消息。enter image description here

1 个答案:

答案 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);

正斜杠用作目录分隔符有什么问题?