2015-05-29 102 views
1

我有一個小問題,在提交表單後顯示錶單值。主要的是當表單被提交時,所有的輸入字段都是空白的。但是,當細節沒有更新時(來自if語句),字段DO顯示。表單提交後不顯示值的輸入字段?

<?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']) 
       )); 

數據庫更新後解決了這個問題,但是我真的不希望有再次查詢數據庫。是否有可能不再查詢?或者它不重要?

+0

哪些輸入字段? –

+0

堅持讓我補充一點。 – Elevant

+0

要澄清輸入字段的值在DATABASE從第一個if語句提交後不顯示。其他else語句顯示字段值。 – Elevant

回答

0

您上面引用的頁面是否爲account.php?

如果是這樣,header("Location: account.php");基本上是將瀏覽器重定向到相關頁面,並因此丟失了所有的發佈數據。