我试图从索引页面调用自定义函数(而不是像其他建议的问题那样使用mysql_ *)。索引页面调用三个自定义函数。前两个正常工作,但第三个功能是抛出和错误:
致命错误:未捕获错误:在F:\ Apache24 \ htdocs \ Site1 \ index.php中调用未定义函数display_index1():45堆栈跟踪:在F:\ Apache24 \ htdocs \ Site1 \中抛出#0 {main}第45行的index.php
这是我的索引页面,它正在调用函数:
<!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>";
}
}
?>
前两个函数成功返回数据。调用第三个是返回错误。
答案 0 :(得分:0)
有一个旧的重复文件导致前两个功能正常工作,但第三个是在最新文件中,这就是它无法正常工作的原因。