gpt4 book ai didi

php - 如何将一行从一个表移动到mysql中的另一个表?

转载 作者:行者123 更新时间:2023-11-28 23:20:12 25 4
gpt4 key购买 nike

帮助。我如何将一行从一个表移动或传输到 mysql 中的另一个表?单击“批准”后,所选行将传输到数据库中的另一个表。请检查我的代码。谢谢!

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);}
?>

最佳答案

如果列 message_id 是一个整数,我认为你应该像这样从 $id 中删除单引号:

$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";

附言您应该在查询中使用准备好的语句而不是直接插入变量,这样可以避免 SQL 注入(inject)。

像这样:

$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();

关于php - 如何将一行从一个表移动到mysql中的另一个表?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42042178/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com