表单提交后输入字段不显示值?

时间:2015-05-29 07:25:58

标签: php

我在提交表单后获取表单值时遇到一些问题。最重要的是当提交表单时,所有输入字段都是空白的。但是当细节没有更新时,字段会显示(来自if statment)。

<?php
require 'core/init.php';

$auth = new Auth();

if (isset($_SESSION['customer_id'])) {
        $rows = DBPDO::getInstance()->get('customer', array(
                array('id', '=', $_SESSION['customer_id'])
            ));

        if ($_SERVER['REQUEST_METHOD'] == 'POST') {

            $password1 = $_POST['password1'];
            // Verify Password Matches Account
            $password1 = $rows->first()->user_salt . $password1;
            $password1 = $auth->hashData($password1);
            // New Password
            $newsalt = $auth->randomString();
            $password2 = $_POST['password2'];
            $newpassword2 = $newsalt . $password2;
            $newpassword2 = $auth->hashData($password2);

            $business = $_POST['businessname'];
            $name     = $_POST['contactname'];
            $email    = $_POST['contactemail'];
            $code     = $_POST['contactcode'];
            $phone    = $_POST['contactphone'];

            if (!empty($password1) && $password1 == $rows->first()->password && empty($password2)) {

                $update = DBPDO::getInstance()->update('customer', $_SESSION['customer_id'], array(
                            'businessName'      => $_POST['businessname'],
                            'contactName'       => $_POST['contactname'],
                            'email'             => $_POST['contactemail'],
                            'code'              => $_POST['contactcode'],
                            'phone'             => $_POST['contactphone'],
                            'deliveryAddress'   => $_POST['deliveryaddress']
                        ));
                $_SESSION['errmsg'] = "Details Updated!";
                header("Location: account.php");

            } elseif (!empty($password1) && $password1 == $user->first()->password && !empty($password2)) {
                echo 'Details and Password Updated';
            } else {
                echo 'Details not Updated';
            }

        }  

    } else {
        header('Location:index.php');
    }


?>

HTML

<form action="<?php echo htmlspecialchars($_SERVER["PHP_SELF"]); ?>" method="post">    
<div class="col-md-6">
    <div class="form-group">
        <label for="businessname">Business Name</label>
        <div class="input-group input-group-lg">
            <input type="text" name="businessname" id="businessname" class="form-control" value="<?php echo $rows->first()->businessName; ?>" aria-required="true"/>
        </div>
    </div>
</form>

我刚刚确认添加:

$rows = DBPDO::getInstance()->get('customer', array(
                    array('id', '=', $_SESSION['customer_id'])
                ));

数据库更新解决了这个问题后,我真的不想再次查询数据库了。有可能不再查询吗?或者不重要吗?

1 个答案:

答案 0 :(得分:0)

您引用的网页是否为account.php?

如果是这样,header("Location: account.php");基本上是将浏览器重定向到相关页面,然后丢失所有帖子数据。

相关问题