인덱스 페이지에서 사용자 정의 함수 (제안 된 다른 질문과 같이 mysql_ *가 아닌)를 호출하려고합니다. 인덱스 페이지가 세 개의 사용자 정의 함수를 호출 중입니다.치명적인 오류 : 알려지지 않은 오류 : 정의되지 않은 함수를 호출하십시오.
<!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 파일은 다음과 같습니다이 함수를 호출 내 인덱스 페이지입니다
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
: 처음 두 제대로 작동하지만 세 번째 기능은 던지고 오류입니다 세 개의 함수가 호출되었습니다.
<?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>";
}
}
?>
처음 두 함수가 데이터를 성공적으로 반환합니다. 세 번째를 호출하면 오류가 반환됩니다.
올바른 파일을 포함 하시겠습니까? 'echo '함수를 정의한다.';''함수 뒤에 display_index1() {...}'; 그 메시지가 나타 납니까? – deceze
또는 코드를 정리하려면 중단 점이있는 디버거를 사용하십시오. – Xenos
'functions.php'는 중요한 파일 인 것 같기 때문에'require()'를 사용하십시오. 파일이 존재하지 않으면 응용 프로그램은 통지 대신에'FATAL'을 보내고 파일없이 계속 진행할 것입니다. ('include'는 덜 엄격합니다.) http://stackoverflow.com/questions/3633900/difference-between-include-and-require-in-php –