更新数据并显示在单页中,无需使用php重新加载页面

时间:2016-10-09 04:08:44

标签: php

我的第一页是所有者详细信息然后我发送id并在驱动程序详细信息页面中显示所有者明智的驱动程序,如果我选择特定驱动程序并在第三页中显示选择驱动程序的信息。在此页面中选择了当前的驱动程序信息,但是当我执行更新查询时,数据未更新我所做的事情。我的问题是在同一页面中显示和更新以及如何传递选择项目的ID

<?php
include("config.php");
$d_idd            = $_GET['d_id'];
$_SESSION['d_id'] = $d_idd;
$d_id             = $_SESSION['d_id'];

//print_r("select * from tbl_multiple_driver where Id = '$d_id'");
die();

$driverUpdate = sqlsrv_query($conn,"select * from tbl_multiple_driver where Id = '$d_id'");

while($driverdetails = sqlsrv_fetch_array($driverUpdate)){
    $id         = $driverdetails['Id'];
    $name       =  $driverdetails['driver_name'];
    $mobile     =  $driverdetails['driver_mobile'];
    $dob        =  $driverdetails['driver_birth_date'];
    $address    =  $driverdetails['driver_address'];
    $location   =  $driverdetails['location'];
    $city       =  $driverdetails['city'];
    $pincode    =  $driverdetails['driver_pincode'];
    $pick_up_area       =  $driverdetails['PickUp_Area'];
    $vehicle_no         =  $driverdetails['vehicle_reg_no'];
    $vehicle_company    =  $driverdetails['V_id'];
    $vehicle_module     =  $driverdetails['V_id'];
    $user_name  =  $driverdetails['username'];
    $reg_date   =  $driverdetails['reg_date'];

    $vehicle = "SELECT * FROM Vehicle where id = '$vehicle_company'";
    $vehicleDisplay   = sqlsrv_query($conn,$vehicle);
    while($vehicleDetails = sqlsrv_fetch_array($vehicleDisplay)){
        $vehicleModel = $vehicleDetails['Vehicle_Model_id'];
    }

    $vehicleMod = "SELECT * FROM Vehicle_Modle where id = '$vehicleModel'";
    $vehicleModDisplay   = sqlsrv_query($conn,$vehicleMod);

    while($vehicleModDetails = sqlsrv_fetch_array($vehicleModDisplay)){
        $vehicleId = $vehicleModDetails['vehicle_id'];
        $vehicleModName = $vehicleModDetails['vehicle_modle_Name'];
    }

    $Mainvehicle = "SELECT * FROM MainVehicle where id = '$vehicleId'";
    $mainvehicleDisplay   = sqlsrv_query($conn,$Mainvehicle);

    while($mainvehicleDetails = sqlsrv_fetch_array($mainvehicleDisplay)){
        $vehiclename = $mainvehicleDetails['vehicle_company'];
    }   
}
?> 


<?php
if(isset($_POST['btnUpdate'])){ 
    //$id       = $_POST['Id'];
    $dName      = $_POST['txtDriverName'];
    $dMobile    = $_POST['txtMobileNumber'];
    $dDob       = $_POST['txtDob'];
    $dAddress   = $_POST['txtDriverAddress'];
    $dLocation  = $_POST['Location'];
    $dCity      = $_POST['city'];
    $dPincode   = $_POST['pincode'];
    $dPickUp    = $_POST['txtPickup'];
    $dVehicleNo = $_POST['txtVehicleNo'];

    //print_r("update tbl_multiple_driver set driver_name = '$dName',driver_mobile='$dMobile',driver_birth_date='$dDob',driver_address='$dAddress',location='$dLocation', city='$dCity',driver_pincode='$dPincode',PickUp_Area='$dPickUp', vehicle_reg_no='$dVehicleNo' where Id= '$id' ");  die();

    $driver_update = "update tbl_multiple_driver set driver_name = '$dName',driver_mobile='$dMobile',driver_birth_date='$dDob',driver_address='$dAddress',location='$dLocation', city='$dCity',driver_pincode='$dPincode',PickUp_Area='$dPickUp', vehicle_reg_no='$dVehicleNo' where Id= '$id' ";

    $res = sqlsrv_query($conn,$driver_update);
    if($res){
        echo '<script language="javascript">';
        echo 'window.location.href = Details.php';
        echo '</script>';
    }

    // header('location:Details.php');  
}
?>  

1 个答案:

答案 0 :(得分:0)

在用户选择时,您必须再次传递ID,然后根据此ID更新信息:

$driver_update = "update tbl_multiple_driver set driver_name = '$dName',
driver_mobile='$dMobile',driver_birth_date='$dDob',‌​driver_address='$dAd‌​dress',
location='$dL‌​ocation', city='$dCity',driver_pincode='$dPincode',
PickUp_Area='$dPick‌​Up', vehicle_reg_no='$dVehicleNo' where Id='".$isession['d_id']."' ";