php在错误消息后重定向到客户更新页面

时间:2017-04-05 23:21:23

标签: php mysql

我有一个应用程序,可以让您从数据库中选择一个客户,然后更新它的信息。如果用户没有输入有效的电子邮件,则会显示一条错误消息,该错误消息存储在单独的php文件中。有谁知道如何包含"返回"再次显示页面的按钮,您可以在哪里更新客户信息?

 <?php include '../view/header.php'; ?>

<div id="main">
<h2>View/Update Customer</h2>

<form action="index.php" method="post" id='aligned'>
    <input type="hidden" name="action" value="update_customer">
    <input type="hidden" name="customer_id" value="<?php echo                            $customer['customerID']; ?>">

    <label>First Name:</label>
    <input type="text" name="first_name" value="<?php echo $customer['firstName']; ?>">
    <br>
    <label>Last Name:</label>
    <input type="text" name="last_name" value="<?php echo $customer['lastName']; ?>">
    <br>
    <label>Address:</label>
    <input type="text" name="address" value="<?php echo $customer['address']; ?>">
    <br>
    <label>City:</label>
    <input type="text" name="city" value="<?php echo $customer['city']; ?>">
    <br>
    <label>State:</label>
    <input type="text" name="state" value="<?php echo $customer['state']; ?>">
    <br>
    <label>Postal Code:</label>
    <input type="text" name="postal_code" value="<?php echo $customer['postalCode']; ?>">
    <br>
    <label>Country Code:</label>
    <input type="text" name="country_code" value="<?php echo $customer['countryCode']; ?>">
    <br>
    <label>Email:</label>
    <input type="text" name="email" value="<?php echo $customer['email']; ?>">
    <br>
    <label>Phone:</label>
    <input type="text" name="phone" value="<?php echo $customer['phone']; ?>">
    <br>
    <label>Password:</label>
    <input type="text" name="password" value="<?php echo $customer['password']; ?>">
    <br>
    <label>&nbsp;</label>
    <input type="submit" value="Update Customer">
    <br><br>

    <a href="?action=search_customer">Search Customer</a>    

</form>

 <?php

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

$action = filter_input(INPUT_POST, 'action');
if($action == NULL) {
$action = filter_input(INPUT_GET, 'action');
if($action == NULL) {
    $action = 'search_customer';
}
}


if ($action == 'search_customer') {
$search = filter_input(INPUT_POST, 'search');
$results = search_customer($search);
include('search_customer.php');

} else if ($action == 'select_customer') {
$customer_id = filter_input(INPUT_POST, 'customer_id');
if ($customer_id == NULL) {
    $error = "Wrong or missing customer ID";
    include ("../errors/error.php");
} else {
$customer = get_customer($customer_id);
include('update_customer.php');
}

} else if ($action == 'update_customer') {
$customer_id = filter_input(INPUT_POST, 'customer_id');
$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');
$country_code = filter_input(INPUT_POST, 'country_code');
$phone = filter_input(INPUT_POST, 'phone');
$email = filter_input(INPUT_POST, 'email', FILTER_VALIDATE_EMAIL);
$password = filter_input(INPUT_POST, 'password');
if ($email == FALSE) {
    $error = "Please enter a valid email";
    include ("../errors/error.php");
} else {
update_customer($first_name, $last_name, $address, $city, $state,       $postal_code, $country_code, $phone, $email, $password, $customer_id);
 header("Location: .");
 }

 }
 ?>

那就是错误文件

<?php include '../view/header.php'; ?>
<div id="main">
<h1 class="top">Error</h1>
<p><?php echo $error; ?></p>

</div>
<?php include '../view/footer.php'; ?>

我试图把

 <a href="?action=select_customer&amp;customer_id=$customer_id"></a>

但是它给了我错误的客户ID错误。

0 个答案:

没有答案