Solution 1 :

INSERT INTO cancel_table(Booking_ID, Name ,Email,Date) 
SELECT id as Booking_id, Name ,Email,Date  
FROM bookings 
WHERE id = 1

try This And Take care To standard of col Name in DB

Problem :

PHP Code in codecancel.php:



$con = new mysqli('localhost', 'root', '', 'halcondentalclinic');

if($con->connect_errno > 0){
    die('Unable to connect to database [' . $db->connect_error . ']');
$sql =   "INSERT INTO cancelled_table SELECT * FROM bookings WHERE booking_id='$id';";

            if ($con->query($sql) === TRUE) {
                $query = "DELETE FROM bookings WHERE booking_id='$id' ";
                if ($con->query($query) === TRUE) {
                    $message = "Success!";

                } else {
                    echo "Error: " . $query . "<br>" . $con->error;
            } else {
                echo "Error: " . $sql . "<br>" . $con->error;

For my Table appointment_calendar.php

        while($row= mysqli_fetch_assoc($query_run))

        <td><?php echo $row['booking_id']; ?> </td>
        <td> <?php echo $row['name']; ?></td>
        <td><?php echo $row['email'];?></td>
        <td><?php echo $row['timeslot'];?> </td>
         <td><?php echo $row['date'];?> </td>
            <form action="codecancel.php" method="post">
                <input type="hidden" name="codecancel_id" value="<?php echo $row['booking_id']; ?> ">
                <button  type="submit" name="codecancel_btn" class="btn btn-danger"> CANCEL</button>

    else {

        echo" No Appointment Found";

I want to transfer/move data if the patient cancels his appointment and the cancel appointment move to cancelled_table in the database then the canceled appointment will be removed to the bookings table in the database this is my table I want to cancel.
enter image description here

if I clicked the cancel button the error is :
enter image description here

Sorry guys I am Newbie in PHP AND MYSQL 🙂


Comment posted by MySQL Insert Where query

Does this answer your question?

Comment posted by yansa

Thanks, jeff I already solved it 🙂 🙂

Comment posted by Strawberry

It’s unusual to want to enact a hard delete under these circumstances. Even if a booking was cancelled, you still might ant some evidence that it had once existed.