Daftar dan Belajar Sekarang!

Mengatasi syntax error: 7 error: cannot insert multiple commands into a prepared statement

foto oceanli
63 Kontribusi 2 Coto
6 bulan yang lalu
saya mau tanya cara mengatasi error karena multiple query
$sql = "
INSERT INTO tb_trash(nama_file, tipe_file, ukuran_file, file, tanggal_upload, id_user) SELECT nama_file, tipe_file, ukuran_file, file, tanggal_upload, id_user from tb_file WHERE id_file = '$id_file' AND id_user = '$id'; 
DELETE FROM tb_file WHERE id_file = '$id_file'; 
";

try {
    $stmt = $db->prepare($sql);
    $stmt->execute();
}
catch (PDOException $e)
{
    echo $e->getMessage();
    die();
}

Jawaban
foto bosque
147 Kontribusi 73 Coto
6 bulan yang lalu
coba kayak gini
$sql = "
INSERT INTO tb_trash(nama_file, tipe_file, ukuran_file, file, tanggal_upload, id_user) VALUES('nama','type','ukuran','file','tgl','id');
SELECT nama_file, tipe_file, ukuran_file, file, tanggal_upload, id_user from tb_file WHERE id_file = '$id_file' AND id_user = '$id'; 
DELETE FROM tb_file WHERE id_file = '$id_file'; 
";
semoga berhasil


Login untuk diksusi di forum sekolah koding