从表中插入另一列PHP

时间:2018-04-26 01:14:33

标签: php mysql sql

我使用PHP将数据从表插入另一个具有附加列的数据,然后从第一个表中删除该行。但是,我似乎无法使其发挥作用:

ListID   FNAME    LNAME
null      null    null
null      null    null

1 个答案:

答案 0 :(得分:0)

您需要在选择中包含附加列作为常量,并且您不需要选择周围的VALUE()。 :

public function insertReq($dID, $bphone)
{
        $stmt = $this->conn->prepare("INSERT INTO RequestedDevices(dID, deviceName, Medical, Description, Educational, DevicePicture, bphone) SELECT id, deviceName, Medical, Description, Educational, DevicePicture, ? WHERE id = ? from TABLE NAME )");
        $flag = $stmt->execute(["someAdditionalColumData", "someID"]);
        $stmt1 = $this->conn->prepare("DELETE FROM DEVICE WHERE id= ? ");
        $flag1 = $stmt1->execute(["originalTableID"]);
        if ($flag & flag1) {
            return ADDED;
        } else {
            return NOT_ADDED;
        }
    }