0
PHP Code in codecancel.php:


 <?php 

if(isset($_POST['codecancel_btn']))
{

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

if($con->connect_errno > 0){
    die('Unable to connect to database [' . $db->connect_error . ']');
}
$id=$_POST['codecancel_id'];
$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

 <?php 
    if(mysqli_num_rows($query_run)>0)
    {
        while($row= mysqli_fetch_assoc($query_run))
        {
            ?>


     <tr>
        <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>
        <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>
            </form>
        </td>

      </tr>
    <?php
        }
    }
    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 :)

yansa
  • 7
  • 3
  • Does this answer your question? [MySQL Insert Where query](https://stackoverflow.com/questions/485039/mysql-insert-where-query) – Brett Gregson Feb 12 '20 at 12:24
  • 1
    The error message states it all. The number of fields within your cancelled_table do not match the number of fields within the bookings table. –  Feb 12 '20 at 12:28
  • Thanks, jeff I already solved it :) :) – yansa Feb 12 '20 at 12:35
  • 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. – Strawberry Feb 12 '20 at 13:26

1 Answers1

0
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

Mustafa Goda
  • 109
  • 6