Problems deleting data from table with ::PDO

Asked

Viewed 94 times

0

Can anyone explain to me what the error or if there is a flaw in the script??

As far as I know this is correct, but it doesn’t work. In the script it takes the ID of who followed and the ID of who was followed and should remove by the parameters WHERE of the line MYSQL, but it’s not deleting..

// SISTEMA DE FOLLOW::USERS
    if(isset($_POST['action']) && $_POST['action'] == 'func_follow') {
        $method     = $_POST['method'];
        $id_de  = $_POST['id_de'];
        $id_para    = $_POST['id_para'];
        $f_data     = time();

        if($method == 'remove'){
            $busca_dados_s = $pdo->prepare("SELECT * FROM `lc_follow` WHERE `f_de` = ? AND `f_para` = ?");
            $busca_dados_s->execute(array($id_de, $id_para));
            if($busca_dados_s->rowCount() > 0){
                $lc_unfollow_dados = $pdo->prepare("DELETE FROM `lc_follow` WHERE `f_de`=:f_de AND `f_para`=:f_para)");
                $lc_unfollow_dados->bindValue(":f_de",$id_de);
                $lc_unfollow_dados->bindValue(":f_para",$id_para);
                $lc_unfollow_dados->execute();

                if($lc_unfollow_dados){
                    echo    '<div class="but_add" onclick="functionAjax_follow(\''.$id_de.'\', \''.$id_para.'\',\'add\')">
                                Seguir
                            </div>';
                } else {
                    echo '::ERRO::';
                }
            }
        }
    }

1 answer

0

When using Prepared statements it is not necessary to escape the values with simple quotes:

DELETE FROM `lc_follow` WHERE `f_de`=':f_de' AND `f_para`=':f_para'
   ----------------------------------^     ^              ^       ^ 
  • before were without, however tbm is not working...

  • @Stoned, add this to see the error, if(!$lc_unfollow_dados->execute()){ print_r($lc_unfollow_dados->errorInfo());}

  • Array ( [0] => 42000 [1] => 1064 [2] => You have an error in your SQL syntax; check the manual that Corresponds to your Mysql server version for the right syntax to use near ')' at line 1 ) -- That was the return

  • @Stonecutter remove the ) at the end of delete. f_para=:f_para)"

  • Can OHH explain why when I run this code it INSERTS twice the same value into the table?? http://i.stack.Imgur.com/7wwCa.png @rray

Browser other questions tagged

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