使用唯一ID从两个表中获取值并插入另一个表中,这是我的代码,例如:" table1"值和" table2"值复制并插入" table3",最后从旧表中删除原始值。
<?php
ini_set('display_errors', 0);
include 'connection/db_connection.php';
$memberid=$_POST['memberid'];
$query=mysql_query("INSERT INTO existing_member (member_id,member_name,dob,gender,address,city,state,phone,email,height,weight,bmi,bp,medical,image_path,joining_date)
SELECT member_id,member_name,dob,gender,address,city,state,phone,email,height,weight,bmi,bp,medical,image_path,joining_date FROM member_registration
WHERE member_id='".$memberid."'" );
/*
$query2=mysql_query("INSERT INTO existing_member (membership_type) SELECT membership_type FROM membership_details
WHERE member_id='".$memberid."'"); */
$query2=mysql_query("INSERT INTO existing_member (membership_type)
SELECT a.membership_type as membership_type FROM membership_details a
INNER JOIN member_registration c ON c.member_id = a.member_id, c.member_name=a.member_name
where a.member_id='".$memberid."'");
if($query2)
{
//$sql=mysql_query("DELETE FROM member_registration WHERE member_id='".$memberid."'");
//$sql1=mysql_query("delete from membership_details where member_id='".$memberid."'");
echo "<script>
alert('Data Deleted Successfully');
window.location.href='close_member.php';
</script>";
}
else
{
echo "User Data Already Exist";
}
答案 0 :(得分:0)
您的第一个查询中有拼写错误:INSERT INTO existing_membe
在其末尾忘记了r
。
此处还缺少y
:if($quer and $query2)
注意强>
不要使用mysql
函数,不推荐使用它们。请改用mysqli
或PDO
。
为避免sql注入攻击,请通过GET
或POST
转义来自用户的变量,或使用预准备语句。