gpt4 book ai didi

PHP 下拉菜单以前可以工作,现在不行了

转载 作者:太空宇宙 更新时间:2023-11-03 10:38:48 25 4
gpt4 key购买 nike

<分区>

所以我对需要做什么才能使这个下拉菜单正常工作一无所知。以前是可以用的,后来改了一些就不行了。显示的错误信息是:

Notice:  Undefined variable: categories in D:\xampp\htdocs\tech_support\product_register\product_register.php on line 19

但我在 index.php 中定义了它:

<?php

require('../model/database.php');

// Get the models needed - work will need to be done in both
require('../model/customer_db.php');
require('../model/product_db.php');
require('../model/registration_db.php');

$action = filter_input(INPUT_POST, 'action');
if ($action == NULL) {
$action = filter_input(INPUT_POST, 'action');
if ($action == null) {
$action = 'product_register';
}
}

//When the user clicks the first link on the home page, bring them to the login page.
if ($action == 'product_register') {
include('customer_login.php');
}

//When the user clicks the login button, the system checks for errors in their typing.
//If no errors are present, proceed to product_register.php.
else if ($action == 'login') {
$email = filter_input(INPUT_POST, 'email', FILTER_VALIDATE_EMAIL);
if ($email == NULL || $email == FALSE) {
$error = 'Invalid email. Try again.';
include('../errors/error.php');
} else {
$custEmail = get_email($_POST['email']);
if ($custEmail) {
$category_name = get_product_name($productName);
$categories = get_products();
$products = get_products_by_name($name);
header("Location: product_register.php");
} else {
$error = 'Invalid email. Try again.';
include('../errors/error.php');
}
}
}
?>

我在我的函数中定义了它

<?php

// Get all the products for the registration dropdown list

function get_products() {
global $db;
$query = 'SELECT * FROM products
ORDER BY productCode';
$statement = $db->prepare($query);
$statement->execute();
return $statement;
}

function get_product_name($productName) {
global $db;
$query = 'SELECT * FROM products
WHERE productCode = :product_code';
$statement = $db->prepare($query);
$statement->bindValue(':product_name', $productName);
$statement->execute();
$product = $statement->fetch();
$statement->closeCursor();
$product_name = $product['name'];
return $product_name;
}

function get_products_by_name($name) {
global $db;
$query = 'SELECT * FROM products
WHERE products.name = :name
ORDER BY productCode';
$statement = $db->prepare($query);
$statement->bindValue(":name", $name);
$statement->execute();
$products = $statement->fetchAll();
$statement->closeCursor();
return $products;
}

product_register.php

<?php include '../view/header.php'; ?>
<?php require('../model/database.php'); ?>
<main>

<h2>Register Product</h2>
<?php if (isset($message)) : ?>
<p><?php echo $message; ?></p>
<?php
else:
$email = filter_input(INPUT_POST, 'email');
?>

<?php endif; ?>
<form action="index.php" method="post">
<label>Customer:</label><br>
<?php echo $email; ?>
<label>Product:</label>
<select>
<?php foreach ( $categories as $category ) : ?>
<option value="<?php echo $cateogry['productCode']; ?>">
<?php echo $category['name']; ?>
</option>
<?php endforeach; ?>
</select><br>

<input type="hidden" name="action" value="register_product">
<input type="submit" value="Register Product">
</form>
</main>
<?php include '../view/footer.php'; ?>

我做错了什么?

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com