2016-10-14 12 views
0

インデックスページからカスタム作成された関数(他の質問と同様にmysql_ *は呼び出さない)を呼び出そうとしています。インデックスページは、3つのカスタム関数を呼び出しています。最初の二つは正常に動作しているが、第三の機能は投げとエラーさ:致命的なエラー:未知のエラー:未定義の関数を呼び出す

Fatal error: Uncaught Error: Call to undefined function display_index1() in F:\Apache24\htdocs\Site1\index.php:45 Stack trace: #0 {main} thrown in F:\Apache24\htdocs\Site1\index.php on line 45

この関数を呼び出している私のインデックスページです:

<!DOCTYPE html> 
    <?php 
    include("includes/connect.php"); 
    include("includes/functions.php"); 
    ?> 
    <html> 
    <head> 
     <title>Ecommerce Website</title> 
     <link rel="stylesheet" type="text/css" href="styles/style.css"> 
     <script src="js/style.js"></script> 
    <body> 
     <div class="container-fluid"> 
      <header> 
       <div class="form"> 
        <form method="get" target="" name="searchbar_form"> 
         <input type="text" name="searchbar" id="searchbar"> 
         <input type="submit" id="search_button" value="Search"> 
        </form> 
       </div> 
      </header> 
      <div class="menubar"> 

        <div class="dropdown"> 
         <button onclick="dropdownToggle()" class="dropdown-button">Shop By Category</button> 

          <ul class="dropdown-content" id="dropdownContent"> 
           Categories 
           <?php getcats(); ?> 
           Brands 
           <?php getbrands(); ?> 
          </ul> 

        </div> 
       <div class="menubar-div"> 
        <ul class="menu-items"> 
         <?php getcats(); ?> 
        </ul> 
       </div> 
       <div class="cart"> 
        <a href="#">Cart</a> 
       </div> 
      </div> 
      <div class="content"> 
       <div class="index_product_row"> 
        <?php display_index1(); ?> 
       </div> 
      </div> 
     </div> 
     <div class="footer"> 
       This is footer 
     </div> 
    </body> 
    </html> 

これは持っているのfunctions.phpファイルであります

<?php 

    function getcats(){ 
     global $con; 

     $get_cats="select * from categories"; 
     $run_cats=mysqli_query($con, $get_cats); 

     while($row_cats=mysqli_fetch_array($run_cats)){ 
      $cat_id = $row_cats['cat_id']; 
      $cat_title = $row_cats['cat_title']; 

      echo "<li><a href='#'>$cat_title</a></li>"; 
     } 
    } 



    function getbrands(){ 
     global $con; 

     $get_brands="select * from brands"; 
     $run_brands=mysqli_query($con, $get_brands); 

     while($row_brands=mysqli_fetch_array($run_brands)){ 
      $brand_id = $row_brands['brand_id']; 
      $brand_title = $row_brands['brand_title']; 

      echo "<li><a href='#'>$brand_title</a></li>"; 
     } 
    } 


    function display_index1(){ 
     global $con; 

     $display_query = "select(product_image, product_title) from products where product_cat='1'"; 
     $display_result = mysqli_query($con, $display_query); 

     while($result_rows = mysqli_fetch_array($display_result)){ 
      $product_image = $result_rows['product_image']; 
      $product_title = $result_rows['product_title']; 

      echo "<img src='/admin/product_images/".$product_image."' width='200' height='200' alt='".$product_title."'/>"; 
      echo "<span id='index_product_title'>".$product_title."</span>"; 
     } 
    } 

?> 

最初の2つの関数はデータを正常に返しています。 3番目を呼び出すと、エラーが返されます。

+5

正しいファイルが含まれていますか?関数 'display_index1(){...}'の後に ';' '関数を定義します。そのメッセージは表示されますか? – deceze

+0

または、コードをクリーンにする場合は、ブレークポイントを持つデバッガを使用します。 – Xenos

+1

'functions.php'は重要なファイルであるようですので、ファイルが存在しない場合、アプリケーションは通知の代わりに' FATAL'を送り、ファイルなしで続行するよう 'require()'を使います。 ( 'include'はそれほど厳密ではありません)http://stackoverflow.com/questions/3633900/difference-between-include-and-require-in-php –

答えて

0

最初の2つの機能が動作する原因となっていた古い重複ファイルがありましたが、最新のファイルで3番目の機能が動作していませんでした。

関連する問題