I am currently having problems with editing fields from a mysql database table using values from a drop-down list. The fields i want to be able to modify and update on mysql database are Type and time which are selected from a drop-down list in my webpage. Whenever i change the 'type' from down menu, it is able to update the database, but has an affect on the 'time' field in the database updates the value to 00:00:00.
This is main part of my code:
$id = $_GET['id'];
if(isset($_POST['update'])){
$type = mysqli_real_escape_string($mysqli, $_POST['testtype']);
$time = mysqli_real_escape_string($mysqli, $_POST['timeslot']);
$query = "UPDATE bookings1 SET Type = '$type', Timeslot = '$time' WHERE booking_id = '$id'";
$sqlquery = $mysqli->query($query);
}
$sqlquery = "SELECT * FROM bookings1 WHERE booking_id = '$id'";
$results = $mysqli->query($sqlquery);
if ($results->num_rows > 0) {
while ($row = $results->fetch_assoc()){
echo '<form method = "post" action = "">';
echo'Type: <select id = name ="testtype" >
<option value =""> '. $row["Type"].' </option>
<option value = "classIV" > Class IV - Cars,light-vans,Motorcaravans (£35.00) </option>
<option value = "classV" > Class V - Private Passenger vehicles & Minibuses (£44.99) </option>
<option value = "classVI" > Class VI - Goods vehicles (£54.99) </option>
<option value = "TaxiMOT" > Taxi MOT - Taxi vehicles (£35.00) </option>
</select></br></br>';
echo'Time: <select id = "timeslot" name ="timeslot" >
<option value =""> '. $row["Timeslot"].' </option>
<option value = "08:30" > 08:30 </option>
<option value = "09:15" > 09:15 </option>
<option value = "10:00" > 10:00 </option>
<option value = "10:45" > 10:45 </option>
<option value = "11:30" > 11:30 </option>
<option value = "12:15" > 12:15 </option>
<option value = "13:00" > 13:00 </option>
<option value = "13:45" > 13:45 </option>
<option value = "14:30" > 14:30 </option>
<option value = "15:15" > 15:15 </option>
<option value = "16:00" > 16:00 </option>
<option value = "16:45" > 16:45 </option>
<option value = "17:30" > 17:30 </option>
</select>
echo '<input type = "submit" = name = "update" value = "update" />';
echo '</form>';
Try formatting the date/time field according to the database column you're putting it in:
If your MySQL column is DATE type:
$date = date('Ym-d', strtotime(str_replace('-', '/', $date)));
If your MySQL column is DATETIME type:
$date = date('Ymd H:i:s', strtotime(str_replace('-', '/', $date)));
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.