简体   繁体   English

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

[英]Input fields not displaying value after form submit?

I am having a little issue getting the form values to display after i have submitted the form. 提交表单后,显示表单值时出现一个小问题。 The main thing is when the form is submitted then all input fields go blank. 最主要的是,提交表单后,所有输入字段都将变为空白。 But the fields DO DISPLAY when Details are not Updated (from if statment). 但是,当“详细信息”未更新时,字段会显示(从if语句开始)。

<?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 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>

i have just confirmed that adding: 我刚刚确认添加:

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

After the Database Update solves the issue, HOWEVER i dont really want to have to query the Database again. 数据库更新解决了问题之后,但是我真的不想再次查询数据库。 Is it possible not to query again? 是否可以不再次查询? Or doesnt it matter much? 还是没关系吗?

Is the page you've quoted above account.php? 您在account.php上方引用的页面是吗?

If so, header("Location: account.php"); 如果是这样,则header("Location: account.php"); is basically redirecting the browser to the page in question, and with that, losing all of the post data. 基本上是将浏览器重定向到相关页面,并因此丢失所有发布数据。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM