I want to keep my last inserted record in the same input field after pressing submit button.
How can retrive last record from database?
I also could not keep the record in the same input field after refresh the page.
<?php
include 'db.php';
$qq=mysqli_query($connect,"select * from 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 INTO `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 * from tbl_trip where route='$route' and 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');
}
}
?>