Reputation: 35
Help. How could I move or transfer one row from one table, to another table in mysql? Once I click "approve", the selected row will transfer to another table in the database. Please check my codes. Thank you!
message.php
<?php
include('connect.php');
$result = mysqli_query($GLOBALS["___mysqli_ston"], "SELECT * FROM message");
while($row = mysqli_fetch_array($result))
{
echo '<tr class="record">';
echo '<td style="background-color: #F8F8F8 ;font-size: 13px; color: maroon;
font-weight: bold; border-left: 1px solid #C1DAD7;">'.$row['name'].'</td>';
echo '<td><div style="font-size: 13px;" align="left">'.$row['address'].'</div></td>';
echo '<td><div style="color:maroon; font-size: 13px;"align="left">Email:<br></div>
<div style="font-size: 13px;"align="left">'.$row['email'].'</div><br>
<div style="font-size: 13px; color:maroon;"align="left">Contact No.<br></div>
<div style="font-size: 13px;"align="left">'.$row['number'].'</div></td>';
echo '<td><div style="font-size: 13px;"align="left">'.$row['services'].'</div></td>';
echo '<td><div style="color:maroon; font-size: 13px;"align="left">Desired Date:<br></div>
<div style="font-size: 13px;"align="left">'.$row['shootdate'].'</div><br>
<div style="font-size: 13px; color:maroon;"align="left">Desired Time: <br></div>
<div style="font-size: 13px;"align="left">'.$row['shoottime'].'</div></td>';
echo '<td><div style="font-size: 13px;"align="left">'.$row['place'].'</div></td>';
echo '<td><div style="font-size: 13px;"align="left">'.$row['message'].'</div></td>';
echo '<td><div align="center">
<a href="acceptmessage.php" id="'.$row['message_id'].'" class="acceptbutton"
title="Click To Approve">Approve</a><br><br>
<a href="deletemessage.php" id="'.$row['message_id'].'" class="delbutton"
title="Click To Decline" style="color:red;">Decline</a></div></td>';
echo '</tr>';
}
?>
acceptmessage.php
<?php
include('../db.php');
if($_GET['id']){
$id = (isset($_GET['id']) ? $_GET['id'] : null);
$sql = "INSERT INTO accept (name, address, email, number, services, shootdate, shoottime, place) SELECT name, address, email, number, services, shootdate, shoottime, place FROM message WHERE message_id='$id'";
mysqli_query($GLOBALS["___mysqli_ston"], $sql);}
?>
Upvotes: 1
Views: 131
Reputation: 331
If the column message_id is an int I think you should remove the single quotes from $id like this:
$sql = "INSERT INTO accept (name, address, email, number, services, shootdate, shoottime, place) SELECT name, address, email, number, services, shootdate, shoottime, place FROM message WHERE message_id=$id";
P.S. you should use prepared statements in your queries instead of inserting variables directly so you can avoid SQL injection.
Something like this:
$sql = "INSERT INTO accept (name, address, email, number, services, shootdate, shoottime, place) SELECT name, address, email, number, services, shootdate, shoottime, place FROM message WHERE message_id=?";
$stmt = $connection->prepare($sql);
$stmt->bindValue(1, $id);
$stmt->execute();
Upvotes: 1