gpt4 book ai didi

php - 从一张表中复制和删除数据

转载 作者:行者123 更新时间:2023-11-30 00:48:17 25 4
gpt4 key购买 nike

我使用了这段代码

<?php
$con=mysqli_connect("localhost","willy","12345","mop");
// Check connection
if (mysqli_connect_errno())
{
echo "Failed to connect to MySQL: " . mysqli_connect_error();
}

$sql="INSERT INTO nominated select * from student where regno = '$_POST[regno]'";
if (!mysqli_query($con,$sql))
{
die('Error: ' . mysqli_error($con));
}
header("location:form5_1.php");

mysqli_close($con);
?>

这会将内容从一个表复制到另一个表,我如何移动(从当前表删除并移动到另一个表)?

最佳答案

1)复制记录

$sql1="INSERT INTO nominated select * from student where regno = ".intval($_POST["regno"]);

2)删除原来的

$sql2="DELETE from student where regno = ".intval($_POST["regno"]);

执行两个查询。请记住在执行此操作之前先清理您的 POST 变量。

编辑:

您询问如何执行这两个操作,以下是您如何使用自己的代码来执行此操作

$sql1="INSERT INTO nominated select * from student where regno = ".intval($_POST["regno"]);
if (!mysqli_query($con,$sql1))
{
// your error checking here
}
else
{
$sql2="DELETE from student where regno = ".intval($_POST["regno"]);
if (!mysqli_query($con,$sql2)
{
// your error checking here
}
}

关于php - 从一张表中复制和删除数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21189466/

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