Question

I have two include files (fill_boxMain.php and fill_boxBottom.php). Both are included from my index.php to fill in the contents of two divs in that order.

As in:

<div><?php require_once 'includes/fill_boxMain.php' ; ?></div>   
<div><?php require_once 'includes/fill_boxBottom.php' ; ?></div>

The first one (fill_boxMain.php) works fine. The second fails no matter how I arrange or change the code - and with the same repeatable errors. i.e. the mysqli_query($dbc,$q) fails.

The SELECT query works fine in phpMyAdmin. I now have the exact same first three lines of code in both 'includes' for testing purposes - shown below. I've read lots of the related posts in SOF and experimented with suggestions but nothing works. That's where I found the suggestion for using "throw new Exception()" instead of die() for error handling - and have redone my code as shown. Thanks for that one.

<?php
require_once 'dbConnect.php' ; //open connection to $dbc
$q = "SELECT * FROM tunes ORDER BY `tunes`.`title` ASC";    
if (!$r = mysqli_query($dbc,$q)) { 
    throw new Exception("Error description: " . mysqli_error($dbc)) ;}  
?>

The error codes I get back are:

Warning: mysqli_query(): Couldn't fetch mysqli in C:\xampp\htdocs\Woodweb\includes\fill_boxBottom.php on line 4

Warning: mysqli_error(): Couldn't fetch mysqli in C:\xampp\htdocs\Woodweb\includes\fill_boxBottom.php on line 4

Fatal error: Uncaught exception 'Exception' with message 'Error description: ' in C:\xampp\htdocs\Woodweb\includes\fill_boxBottom.php:4 Stack trace: #0 C:\xampp\htdocs\Woodweb\index.php(31): require_once() #1 {main} thrown in C:\xampp\htdocs\Woodweb\includes\fill_boxBottom.php on line 4

That 'Fatal Error' looks significant but I have no idea what it means. Any help solving this is appreciated.

Was it helpful?

Solution

It looks like your issue is with the require_once of the dbConnect.php. I am assuming fill_main also calls the db by require_once "dbConnect.php";. If this is the case when it get's to fill_bottom the require_once will not trigger and the dbConnect.php code won't happen.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top