I am trying to call a custom made function (not mysql_* as in other questions suggested) from the index page. The index page is calling three custom functions. The first two are working correctly but the third function is throwing and error:
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
This is my index page which is calling the function:
<!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>
This is the functions.php file which has the three called functions:
<?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>";
}
}
?>
The first two functions are returning data successfully. Calling the third is returning the error.