What I am trying to do is print the first name and last name of a customer from my database onto a php document and I am getting errors.
These are the errors:
Notice: Undefined index: fName in D:\xampp\htdocs\tech_support\product_register\index.php on line 36
Notice: Undefined index: lName in D:\xampp\htdocs\tech_support\product_register\index.php on line 37
This is a new error and I don't know what that means.
Here is the code that I have made:
index.php:
<?php
// Get your db connection file, be sure it has a new connection to the
// tech support database
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);
$firstName = filter_input(INPUT_POST, 'fName');
$lastName = filter_input(INPUT_POST, 'lName');
if ($email == NULL || $email == FALSE) {
$error = 'Invalid email. Try again.';
include('../errors/error.php');
} else {
$custEmail = get_email($_POST['email']);
$fName = get_fname($_POST['fName']);
$lName = get_email($_POST['lName']);
if ($custEmail) {
$fName = get_fname($firstName);
$lName = get_lname($lastName);
$categories = get_products();
include('product_register.php');
} else {
$error = 'Invalid email. Try again.';
include('../errors/error.php');
}
}
}
customers_db.php:
<?php
//Get a customer by their email address and
//check if the data entered in the form is true or false
function get_email($email) {
global $db;
$query = 'SELECT * FROM customers WHERE email = :email';
$statement = $db->prepare($query);
$statement->bindValue(':email', $email);
$statement->execute();
$status = false;
if($statement->rowCount()){
$status = true;
}
return $status;
}
//Get customer by their first name
function get_fname($firstName) {
global $db;
$query = 'SELECT * FROM customers WHERE firstName = :firstName';
$statement = $db->prepare($query);
$statement->bindValue(':firstName', $firstName);
$statement->execute();
}
//Get customer by their last name
function get_lname($lastName) {
global $db;
$query = 'SELECT * FROM customers WHERE lastName = :lastName';
$statement = $db->prepare($query);
$statement->bindValue(':lastName', $lastName);
$statement->execute();
}
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');
$firstName = filter_input(INPUT_POST, 'firstName');
$lastName = filter_input(INPUT_POST, 'lastName');
?>
<?php endif; ?>
<form action="index.php" method="post">
<label>Customer:</label>
<?php echo $fName; ?> <?php echo $lName; ?><br>
<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'; ?>
This is what its supposed to do its supposed to print the name of the customer like this:
Any ideas on how to fix this problem?