Move row to another table in the PHP PDO database

Asked

Viewed 111 times

-1

I have a table of movies on my site that has the option to edit and delete. I’m having a hard time deleting the film from my chart. What I want to do is: When you click delete, it moves the row to another table of the same type by backing up. After it move, delete the row from the current table.

What I can’t do is pass the field id on the link. When I click the button to "delete" from the table, it does not pass the desired value, passing only the value 2.

Follows my code:

Boot

<a href="painel_adm_deletefilme.php?idFilme='.$dados['idFilme'].'"><input class="btn btn-danger" name="excluirFilme" value="Sim" class="btn btn-danger"></input></a>

painel_adm_deletefilme

<?php

session_start(); include_once 'connects Anco.php';

$id = $_GET["idFilme"];

$envia = "INSERT INTO filmesDelet (idFilme, filme, descricao, genero, anoLancamento, faixaEtaria, trailer) 
SELECT idFilme, filme, descricao, genero, anoLancamento, faixaEtaria, trailer 
from filmes where idFilme = '$id'";

$insere_bd = $conecta->prepare($envia);

if($insere_bd->execute()){
    echo 'sucesso';
}else{
    echo 'failed';
}

?>

The code does not return any error. It goes directly into the success if, and the table was not passed to the desired row. Whenever I click to "delete" it passes the id of value 2. inserir a descrição da imagem aqui

2 answers

1


But why all this work? Is it really necessary to move to another table? Because you do not create an "deleted (bool)" column and mark it as true when the client exlcuires the record, then show only the not deleted movies "Where exluidos = false"

But if you really want to "copy and paste" keeping the same ID, first you should check if your database ID is not auto incremented and then just load the data and give Insert in the backup table.

Vlw!

  • I will do as you said, set an attribute in the table and show according to the boolean value.

0

That part of the code doesn’t look right:

<a href="painel_adm_deletefilme.php?idFilme='.$dados['idFilme'].'">

You put php code right into html. I think it would work if I switched to it:

<a href="painel_adm_deletefilme.php?idFilme=<?=$dados['idFilme'];?>">
  • I forgot to mention, that chunk of code is inside an echo foreach, so I didn’t have to open the php tag.

  • But when you hover over the link no error message appears in the status bar that shows the link path?

Browser other questions tagged

You are not signed in. Login or sign up in order to post.