Can someone please help me understand why the below function works in option.php but does not work in main.php? From what I'm seeing, it looks as if the query is not going through when the function is called on main.php; however, it clearly goes through on option.php.
custom_functions.php
function fetch_options(){
global $connection;
$query = "SELECT * FROM table";
$result = mysqli_query($connection, $query);
while($row = mysqli_fetch_assoc($result)){
echo "<option value=\"{$row['a']}\">{$row['b']}</option>";
}
mysqli_free_result($result);
mysqli_close($connection);
}
option.php
<?php
require_once('lib/db.php');
require_once('lib/custom_functions.php');
echo "<select><option value=\"0\">Unknown</option>";
fetch_options();
echo "</select>";
?>
main.php
<?php
require_once('lib/db.php');
require_once('lib/custom_functions.php');
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Main</title>
<link href="css/bootstrap.css" rel="stylesheet">
<!--[if lt IE 9]>
<script src="https://oss.maxcdn.com/html5shiv/3.7.2/html5shiv.min.js"></script>
<script src="https://oss.maxcdn.com/respond/1.4.2/respond.min.js"></script>
<![endif]-->
</head>
<body>
<?php include('lib/nav.php'); ?>
<div class="container-fluid">
<div class="row">
<div class="col-lg-2" style="padding:none;background-color:#ccc;min-height: calc(100vh - 52px);">
</div>
<div class="col-lg-10" style="padding:none;" id="page2">
<select class="form-control" id="e_CR" name="craft">
<option value="0">Unknown</option>
<?php fetch_options(); ?>
</select>
</div>
</div>
</div>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.2/jquery.min.js"></script>
<script src="js/validate.js"></script>
<script src="js/bootstrap.js"></script>
<script src="js/jfunctions.js"></script>
</body>
</html>