Keep last inserted record in the input field using php -
i want keep last inserted record in same input field after pressing submit button.
how can retrive last record database?
i not keep record in same input field after refresh page.
<?php include 'db.php'; $qq=mysqli_query($connect,"select * tbl_route"); ?> route: <select name="route" id="route"> <option value="" disabled selected> : : select : : </option> <?php $n=1; while($a=mysqli_fetch_array($qq)) { ?> <option value="<?php echo $a['r_id']; ?>"><?php echo $a['route1']; ?></option> <?php $n++; } ?> </select> driver: <input type="text" name="driver" id="driver" value="<?php isset($_post['driver']) echo $_post['driver']; ?>">
insertion coding
<?php if(isset($_post['submit'])) { session_start(); include 'db.php'; $route = $_post['route']; $driver = $_post['driver']; $driver_name = $_post['driver_name']; $vehicle = $_post['vehicle']; $passenger = $_post['passenger']; $date=date('y-m-d h:i:s'); $status=1; $query = mysqli_query($connect,"insert `motorpark-db`.`tbl_trip` (`route`, `dm`, `dn`, `vehicle`, `passenger`, `t_status`, `trip_date`)values('$route', '$driver', '$driver_name', '$vehicle', '$passenger', '$status', '$date')"); $q=mysqli_query($connect,"select * tbl_trip route='$route' , dm='$driver'"); $row=mysqli_fetch_array($q); $route=$row['route']; $dm=$row['dm']; $dn=$row['dn']; $_session['route']=$route; $_session['dm']=$dm; $_session['dn']=$dn; if($query) { header('location:trip_details.php'); } else { header('location:trip_details.php'); } } ?>
this might you.
$query = mysqli_query($connect,"insert `motorpark-db`.`tbl_trip` (`route`, `dm`, `dn`, `vehicle`, `passenger`, `t_status`, `trip_date`)values('$route', '$driver', '$driver_name', '$vehicle', '$passenger', '$status', '$date')"); $last_inserted-id = mysqli_insert_id($connect); $get_record = mysqli_query($connect,"select * tbl_trip id = '$last_inserted-id'"); $row=mysqli_fetch_array($get_record); if($query) { header("location:trip_details.php?vals=" . urlencode(serialize($row))); }
in view page:
if (isset($_get['vals'])) { $values = unserialize(urldecode($_get['vals'])); } <select name="route" id="route"> <?php $n=1; while($a = mysqli_fetch_array($qq)) { ?> <option value="<?php echo $a['r_id']; ?>" <?php if (isset($values['route'])) { if ($values['route'] == $a['r_id']) { ?> selected <?php } }?>><?php echo $a['route1']; ?></option> <?php $n++; } ?> </select> <input type="text" name="driver" id="driver" value="<?php (isset($values['driver']))? $values['driver'] : '' ?>">
Comments
Post a Comment