我有3個表:控制器,allot_compnts和prev_allot_compnts,3代表具有相同的字段,當我點擊提交按鈕,在allot_compnts值複製到prev_allot_compnts和allot_compnts刪除如何在MySQL中添加兩個表中的兩列?
代碼:
[email protected]$_POST['submit']
$type = isset($_POST['comp_type'])? $_POST['comp_type'] : '';
$name = isset($_POST['comp_name'])? $_POST['comp_name'] :'';
$comp = isset($_POST['num_comp'])? $_POST['num_comp'] :'';
//Insert
$sql1="INSERT INTO prev_alloted_comp(id,comp_type,comp_name,num_comp)
SELECT comp_type,comp_name,num_comp FROM alloted_comp WHERE id='$id'" ;
//Delete
$sql2="delete from alloted_comp where id='$id'";
//Here i'm trying to update controller table
if($type === 'Controller'){
$sql3= "UPDATE comp_controller SET
num_comp=(num_comp+$_POST[num_comp]) WHERE comp_name ='$name'
ON DUPLICATE KEY UPDATE num_comp=num_comp+'$_POST[num_comp]'";
}
我試圖更新基於$ _ POST [num_comp]在控制器表num_comp,但在控制表中的值不更新
我是新來這個,請任何一個可以幫助我如何做到這一點
更新:我剛剛更新了我的代碼
[email protected]$_POST['submit']
$type = isset($_POST['comp_type']);
$name = isset($_POST['comp_name']);
$comp = isset($_POST['num_comp']);
//Insert
$sql1="INSERT INTO prev_alloted_comp(id,comp_type,comp_name,num_comp)
SELECT comp_type,comp_name,num_comp FROM alloted_comp WHERE id='$id'" ;
//Delete
$sql2="delete from alloted_comp where id='$id'";
//Here i'm trying to update controller table
if($type === 'Controller'){
$sql3= "UPDATE comp_controller SET
num_comp=(num_comp+$_POST[num_comp]) WHERE comp_name ='$name'";
}
西爾不工作
無效的語法'(num_comp + $ _ POST [num_comp])',正確地轉義字符串,變量 – Thamilan
@Thamilan實際上被解析並被'$ _POST'中的相應值替換。雖然它仍然是對sql注入課程的公開邀請。 (用一堆E_NOTICE來使用未定義的常量,但php在這一點上認爲它是一個字符串) – ccKep
@Thamilan,謝謝你的評論,我只是想添加帖子值,是否有任何修改'(num_comp + $ _POST [num_comp])' – kiran