插入从表到另一列的另一列PHP插入

  • 本文关键字:一列 插入 PHP php mysql sql
  • 更新时间 :
  • 英文 :


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

public function insertReq($dID, $bphone)
    {
            $stmt = $this->conn->prepare("INSERT INTO RequestedDevices(dID, deviceName, Medical, Description, Educational, DevicePicture, bphone) VALUES((SELECT id, deviceName, Medical, Description, Educational, DevicePicture WHERE id = ?), ?)");
           $stmt->bind_param("ss", $dID, $bphone);
            $flag = $stmt->execute();
            $stmt1 = $this->conn->prepare("DELETE FROM DEVICE WHERE id= ? ");
            $stmt1->bind_param("s", $dID);
            $flag1 = $stmt1->execute();
            if ($flag & flag1) {
                return ADDED;
            } else {
                return NOT_ADDED;
            }
        }

您需要在选择中将附加列作为常数包含,并且您不需要围绕选择的值((。:

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;
        }
    }

相关内容

  • 没有找到相关文章

最新更新