2015-05-29 84 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");基本上是将浏览器重定向到相关页面,并因此丢失了所有的发布数据。