1

I have the following script to delete selected items from a table.

<?php 
    class deleteNews extends Generic 
    {
        private $error;
        private $news_id_delete;

        function __construct() 
        {
            if (empty($_POST['deleteCheck'])) {
                echo '<div class="alert alert-danger" role="alert"> <strong>Erro!</strong> Nenhuma notícia foi selecionada! </div>';
            }

            if(isset($_POST['deleteCheck'])) {
                $this->news_id_delete = parent::secure($_POST['deleteCheck']);

                $params = array(
                    ':news_id_delete'       => $this->news_id_delete,
                );

                foreach($this->news_id_delete as $delete) {
                    $sql = "DELETE FROM `login_news` WHERE `news_id` = $delete;";
                    parent::query($sql, $params);
                }

                echo '<div class="alert alert-success" role="alert"> <strong>Sucesso!</strong> Sua notícia foi publicada! </div>';

           }
       }
    }

    if (isset($_POST['deleteBtn'])) {   
        $addUser = new deleteNews();                
    }    
?>

It works fine, the problem is that each time it executes, it returns the following Notice:

Notice: Array to string conversion

How can I get rid of this notice?

Joy Cooper
  • 43
  • 1
  • 5

1 Answers1

1

remove $params from

parent::query($sql, $params);

as I think your query is complete and doesn't need any extra params to be inserted in sql statement as id to be deleted is already passed in the query.

$sql = "DELETE FROM `login_news` WHERE `news_id` = $delete;"

Also $params is an array of arrays which is why you get this error from query function

jitendrapurohit
  • 9,435
  • 2
  • 28
  • 39