With this, I'm needing to first off start with the search bar that searches for the last name of a customer. Once the search button is pressed, in a table below it is to produce the full name of the customer, their email address and their city they reside in. Beside every row in the table there is a select button that when pressed, takes you to another page that displays all of their contact information. The way the code is designed is for the search customer_search.php to go through the index.php through to the customer_display.php page to display the customers full information. On the customer_display.php page. The customers information is to come up that is associated with the customer that was selected in the customer_search.php page. The customer_display.php is displayed with the help of the index.php page. Sorry if this is a bit hard to understand. Hopefully the code attached will help with what I am talking about.
Chloe_6 0 Newbie Poster
<?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" value="Update Customer" /><br>
</form>
<p><a href="customer_search.php">Search Customers</a></p>
</main>
<?php include '../view/footer.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" name="search_customers" class="search">
<input type="submit" name="submit" class="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'; ?>
<?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');
}
?>
- 1 Contributor
- 0 Replies
- 46 Views
Be a part of the DaniWeb community
We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.