2014-01-17 50 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語句不存在。您必須將慾望記錄插入新表並從舊錶中刪除。

相關問題