嗨,我正在修改我的一项练习的代码。修改后的代码确实运行,但我不断收到此错误:
"Undefined index: category_id in C:\xampp\htdocs\ex_starts\ch04_ex1\add_category.php on line 5"
您能否告诉我应该如何在以下代码中初始化 category_id 的索引?
谢谢!!
这是我的代码:
<?php // Get the category data
$category_id = $_POST['category_id'];
$name = $_POST['name']; // Validate inputs
if ( empty($name) ) {
$error = "Invalid category data. Check all fields and try again.";
include('error.php');
} else {
// If valid, add the product to the database
require_once('database.php');
$query = "INSERT INTO categories
(categoryID, categoryName)
VALUES
('$category_id', '$name')";
$db->exec($query);
// Display the Category List page
include('category_list.php');
}
?>