-4

I have a strong feeling that the IF or mysql_query won't work. (I guess it is the IF)

if(isset($_POST['delete']) && $admin == "3"){
        $query = mysql_query("DELETE FROM dis_posts WHERE post_id = '".$posts['post_id']."'");
        $result = mysql_query($query);
        header("Location: ". $_SERVER['REQUEST_URI']);
    }

Help please? Thanks in advance.

  • 3
    It would be helpfull to know what DOES and what SHOULD happen. – Dragony Jan 05 '14 at 15:09
  • 4
    You're calling `mysql_query()` _twice_. First with the sql string (correctly) and immediately after with the boolean it returned (incorrect) – Michael Berkowski Jan 05 '14 at 15:09
  • It should delete the row inside the "dis_posts" table, row: "post_id". – Billy_2lgit_2qt Jan 05 '14 at 15:10
  • Please see [How can I prevent SQL injection in PHP](http://stackoverflow.com/questions/60174/how-can-i-prevent-sql-injection-in-php) and begin learning about prepared statements in PDO or MySQLi. The `mysql_*()` extension is deprecated in PHP 5.5 and should not be used for new code. – Michael Berkowski Jan 05 '14 at 15:12
  • Have you tried printing the contents of the POST variable and $admin variable to make sure they contain what you expect? – James Smith Jan 05 '14 at 15:12

2 Answers2

0

If your database connection is alright then
Try Like this:

   if(isset($_POST['delete']) && isset($admin) && $admin == "3"){
            $query = mysql_query("DELETE FROM dis_posts WHERE post_id = '".$posts['post_id']."'");
         if(!$query){

           echo "could not updated!";
         }else {
            header("Location: ". $_SERVER['REQUEST_URI']);
         }
   }
Awlad Liton
  • 9,366
  • 2
  • 27
  • 53
0

I could be wrong, but it seems like maybe this is what you are trying to do...

if(isset($_POST['delete']) && $admin == "3"){
    $query = "DELETE FROM dis_posts WHERE post_id = '".$posts['post_id']."'";
    $result = mysql_query($query);
    if($result){
        header("Location: ". $_SERVER['REQUEST_URI']);
    }
}
jwitt98
  • 1,194
  • 1
  • 16
  • 30
  • Sorry... didn't see Awlad's post until my screen refreshed. Same concept with the addition of the "echo" statement for some visual feedback. – jwitt98 Jan 05 '14 at 15:40