I have started coding in php to produce a customer search, where you search for the last name. When you hit the search button any customer with that specific last name will show up in a table below along with their email address and city they reside in. Beside each customer listed there is a select button that will take you to their full information. I'm needing help with getting it all to work correctly. I have put in all of the coding for multiple pages, but in the customer_display.php where it shows country, that is needing to be a drop down that shows all of the countries that is in the data base under the table "Countries". This is all suppose to be working off of the database.
customer_search.php
<?php include '../view/header.php'; ?>
<main>
<h2>Customer Search</h2>
<!-- display a search form -->
<form action="index.php" method="post">
<p>Last Name:
<input type="text" action="search_customers" name="action">
<input type="submit" value="Search"></p>
</form>
<?php if (isset($message)) : ?>
<p><?php echo $message; ?></p>
<?php else if ($customers) : ?>
<h2>Results</h2>
<table>
<tr>
<th>Name</th>
<th>Email Address</th>
<th>City</th>
<th> </th>
</tr>
<?php foreach ($customers as $customer) : ?>
<tr>
<td><?php echo htmlspecialchars($customer['first_name', 'last_name']); ?></td>
<td><?php echo htmlspecialchars($customer['email']); ?></td>
<td><?php echo htmlspecialchars($customer['city']); ?></td>
<td><form action="index.php" method="post">
<input type="hidden" name="action"
value="display_customers">
<input type="hidden" name="name"
value="<?php echo htmlspecialchars($customer['first_name', 'last_name']); ?>">
<input type="submit" value="Select">
</form></td>
</tr>
<?php endforeach; ?>
</table>
<?php endif; ?>
</main>
<?php include '../view/footer.php'; ?>
customer_display.php
<?php include '../view/header.php'; ?>
<main>
<!-- display a table of customer information -->
<h2>View/Update Customer</h2>
<form action="index.php" method="post" id="aligned">
<input type="hidden" name="action" value="display_customer">
<label>First Name:</label>
<input type="text" name="first_name"><br>
<label>Last Name:</label>
<input type="text" name="last_name"><br>
<label>Address:</label>
<input type="text" name="address"><br>
<label>City:</label>
<input type="text" name="city"><br>
<label>State:</label>
<input type="text" name="state"><br>
<label>Postal Code:</label>
<input type="text" name="postal_code"><br>
<label>Country Code:</label>
<input type="text" name="country_code"><br>
<label>Phone:</label>
<input type="text" name="phone"><br>
<label>Email:</label>
<input type="text" name="email"><br>
<label>Password:</label>
<input type="text" name="password"><br>
<label> </label>
<input type="submit" action="update_customer" value="Update Customer" /><br>
</form>
<p><a href="customer_search.php">Search Customers</a></p>
</main>
<?php include '../view/footer.php'; ?>
index.php
<?php
require('../model/database.php');
require('../model/customer_db.php');
ini_set('display_errors', '1');
ini_set('display_startup_errors', '1');
error_reporting(E_ALL);
$action = filter_input(INPUT_POST, 'action');
if ($action === NULL) {
$action = filter_input(INPUT_GET, 'action');
if ($action === NULL) {
$action = 'display_customers';
}
}
//instantiate variable(s)
$last_name = '';
$customers = array();
if ($action == 'search_customers') {
$last_name = filter_input(INPUT_POST, 'last_name');
$custoemrs = get_customers_by_last_name($last_name);
$customers = get_customers();
include('customer_display.php');
} else if ($action == 'display_customers') {
$last_name = filter_input(INPUT_POST, 'last_name');
if ($last_name != false) {
display_customers($last_name);
}
$customers = get_customers();
include('customer_display.php');
} else if ($action == 'display_customer') {
include('customer_search.php');
} else if ($action == 'update_customer') {
$first_name = filter_input(INPUT_POST, 'first_name');
$last_name = filter_input(INPUT_POST, 'last_name');
$address = filter_input(INPUT_POST, 'address');
$city = filter_input(INPUT_POST, 'city');
$state = filter_input(INPUT_POST, 'state');
$postal_code = filter_input(INPUT_POST, 'postal_code');
$phone = filter_input(INPUT_POST, 'phone');
$email = filter_input(INPUT_POST, 'email');
$password = filter_input(INPUT_POST, 'password');
$country_name = filter_input(INPUT_POST, 'country_name');
include('customer_search.php');
}
?>
The way it is suppose to work is when you hit on the button, it goes into the index.php finds the action and then posts to the required page. So the search button is suppose to take any customer with the last name and show it on the table below on the same page. The select button is taking that customer and showing all of their information on the customer_display.php page and then the update customers button is to take you back to the customer_search.php page to show that it has been successfully updated.