[英]Input fields not displaying value after form submit?
提交表單后,顯示表單值時出現一個小問題。 最主要的是,提交表單后,所有輸入字段都將變為空白。 但是,當“詳細信息”未更新時,字段會顯示(從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
<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'])
));
數據庫更新解決了問題之后,但是我真的不想再次查詢數據庫。 是否可以不再次查詢? 還是沒關系嗎?
您在account.php上方引用的頁面是嗎?
如果是這樣,則header("Location: account.php");
基本上是將瀏覽器重定向到相關頁面,並因此丟失所有發布數據。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.