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

ToDoList Manager

ToDoList

Title Description

value="">

value="">

Add Product

List Categories

© ToDoList.

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!