2014-01-17 150 views
0

删除数据我用这个代码副本,并从一个表

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

这个副本从一个表到另一个内容,如何移动(从当前表中删除,并移动到另一个表)?

+0

在sql中没有“移动”命令。你将INSERT'放入一个表中,然后从另一个表中删除。同样,你很容易受到[SQL注入攻击](http://bobby-tables.com)的影响,所以请尽情享受你的服务器pwn3d。 –

+0

是不是使用'DELETE'语句来阻止语句执行之间插入新记录的原因? – regulus

+0

@MarcB:我不介意漏洞问题哥们,这只是为我的项目:) – wilfredcool007

回答

0

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 
    } 
} 
+0

你会介意如何执行这两个查询,我是新来的php .... 继承人我的完整代码 http://pastebin.com/DDvXgqw8 – wilfredcool007

+0

你可以从这个评论中删除你的代码,并将它附加到你的问题,使其更具可读性?我很乐意协助 –

+0

完成好友..完整的代码发布。感谢您的帮助:) – wilfredcool007

0

的举动SQL语句不存在。您必须将欲望记录插入新表并从旧表中删除。

相关问题