Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Fundamentals Of Database Systems

Authors: Ramez Elmasri, Shamkant B. Navathe

7th Edition Global Edition

1292097612, 978-1292097619

More Books

Students also viewed these Databases questions