Question
Hello! I need help figuring out why I can getting this warning! Warning : Trying to access array offset on value of type bool in
Hello! I need help figuring out why I can getting this warning!
Warning: Trying to access array offset on value of type bool in C:\xampp\htdocs\ToDoList3\index.php on line 19
I am doing a ToDoList using PHP. Below is my code so far:
The problem is happening on line 19 with $category_name. I am not sure why it is happening. It later continues down to line 73 where it's basically Echoing the name to display information on the screen or whatever the first categoryName in the table would be. Any guesses as to why it is acting this way?
Index.php:
require_once('database.php');
// Get category ID
if (!isset($category_id)) {
$category_id = filter_input(INPUT_GET, 'category_id',
FILTER_VALIDATE_INT);
if ($category_id == NULL || $category_id == FALSE) {
$category_id = 1;
}
}
// Get name for selected category
$queryCategory = 'SELECT * FROM categories
WHERE categoryID = :category_id';
$statement1 = $db->prepare($queryCategory);
$statement1->bindValue(':category_id', $category_id);
$statement1->execute();
$category = $statement1->fetch();
$category_name = $category['categoryName'];
$statement1->closeCursor();
// Get all categories
$query = 'SELECT * FROM categories
ORDER BY categoryID';
$statement = $db->prepare($query);
$statement->execute();
$categories = $statement->fetchAll();
$statement->closeCursor();
// Get products for selected category
$queryProducts = 'SELECT * FROM todoitems
WHERE categoryID = :category_id
ORDER BY ItemNum';
$statement3 = $db->prepare($queryProducts);
$statement3->bindValue(':category_id', $category_id);
$statement3->execute();
$products = $statement3->fetchAll();
$statement3->closeCursor();
?>
ToDoList Manager
ToDoList
Categories
- ">
Title | Description | |
---|---|---|
Add Product
List Categories
© ToDoList.
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started