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.
if I clicked the cancel button the error is :
Sorry guys I am Newbie in PHP AND MYSQL :)