在没有ajax的情况下插入和读取数据?

时间:2015-12-17 03:41:25

标签: php jquery ajax mysqli

<?php
$cust_id = $_SESSION["cust_id"];

$sql = "SELECT * FROM customers WHERE cust_id='$cust_id' AND cust_status='NORMAL'";

$user_fetch = mysqli_query($mysqli,$sql);

$numrows = mysqli_num_rows($user_fetch);

if ($numrows <1 ) {
echo "This customer does not exist for log in check email.";
session_destroy();
echo '<script>window.location.assign("../sign-in.php")</script>';

exit();
}

while ($row = mysqli_fetch_array($user_fetch, MYSQLI_ASSOC)) {

  $cust_id        = $row['cust_id'];
  $cust_fname     = $row['cust_fname'];
  $cust_lname     = $row['cust_lname'];
  $cust_contact   = $row['cust_contact'];
  $cust_email     = $row['cust_email'];

  $cust_address   = $row['cust_address'];
  $cust_city      = $row['cust_city'];
  $cust_pin       = $row['cust_postal_code'];
  $cust_state     = $row['cust_state'];
  $cust_country   = $row['cust_country'];

  $cust_payType   = $row['cust_payType'];
  $cust_payID     = $row['cust_payID'];

  $cust_carCount  = $row['cust_car_count'];
  //$cust_orders    = $row[''];
  $cust_status    = $row['cust_status'];
}

if (isset($_POST['submitDetails'])) {

$CustFname    = $mysqli->real_escape_string($_POST['custFName']);
$custLname    = $mysqli->real_escape_string($_POST['custLName']);
$custCont  = $mysqli->real_escape_string($_POST['custContact']);
$custEmail    = $mysqli->real_escape_string($_POST['custEmail']);

$sql = "UPDATE customers SET cust_fname='$CustFname', cust_lname='$custLname', cust_email='$custEmail', cust_contact='$custCont' WHERE cust_id='$cust_id'";

if (!isset($_POST['custFName']) || strlen($_POST['custFName'])>1) {
if (!isset($_POST['custLName']) || strlen($_POST['custLName'])>1) {
if (!isset($_POST['custContact']) || strlen($_POST['custContact'])>1) {
if (!isset($_POST['custEmail']) || strlen($_POST['custEmail'])>1) {
if (!isset($_POST['custPhoto']) || strlen($_POST['custPhoto'])>1) {
if ($mysqli->query($sql)=== TRUE) {
                          echo'<div id="success-alert" class="alert alert-success"><a href="#" class="close" data-dismiss="alert" aria-label="close">&times;</a><strong>Congratulations!</strong> You Have added new car in your account .</div>';                              
                        }
                      }
                    }
                  }
                }
              }
              else{echo "Something is missing in username";}
            }

        ?>


<form class="form-horizontal" action="" method="POST" enctype="multipart/form-data">

                  <div class="form-group">
                    <label for="inputEmail" class="col-sm-2 control-label">First Name</label>
                    <div class="col-sm-10">
                      <input type="text" name="custFName" class="form-control" id="fname" value="<?php echo $cust_fname;?>">
                    </div>
                  </div>

                  <div class="form-group">
                    <label for="inputEmail" class="col-sm-2 control-label">Last Name</label>
                    <div class="col-sm-10">
                      <input type="text" name="custLName" class="form-control" id="lname" value="<?php echo $cust_lname;?>">
                    </div>
                  </div>

                  <div class="form-group">
                    <label for="inputContact" class="col-sm-2 control-label">Contact Number</label>
                    <div class="col-sm-10">
                      <input type="text" name="custContact" class="form-control" id="inputContact" value="<?php echo $cust_contact; ?>">
                    </div>
                  </div>

                  <div class="form-group">
                    <label for="inputEmail" class="col-sm-2 control-label">Email</label>
                    <div class="col-sm-10">
                      <input type="email" name="custEmail" class="form-control" id="inputEmail" value="<?php echo $cust_email;?>">
                    </div>
                  </div>

                  <div class="form-group">
                    <label for="inputSliderImage" class="col-sm-2 control-label">Photo</label>
                    <input id="inputSliderImage" name="custPhoto" type="file" style="padding-left:13px;">
                  </div>

                  <div class="form-group">
                    <div class="col-sm-offset-2 col-sm-10">
                      <button type="submit" name="submitDetails" class="btn btn-primary">Submit</button>
                    </div>
                  </div>
            </form>

我使用上述查询从我的数据库中获取数据并将其插入。现在我想更新文本框的新值。我怎么能这样做?

第一个查询是从数据库中获取数据并在表单的texbox中显示它。

第二个是数据更新查询,用于将数据从texbox更新到数据库,它工作正常,但新更新的数据现在显示在文本框中。

1 个答案:

答案 0 :(得分:0)

您在更新结果之前提取结果。切换订单。如果您需要稍后显示html,只需将其存储在临时变量中,并在适当时将其回显。