How to properly delete a row using PHP & PDO
<p>I looked up multiple ways to delete a specified row in PDO, and I am a beginner in learning PHP/PDO. I originally used Mysql_query and the like, but I am now told that it is bad practice to use. I have a script to delete a news post by id when the delete button is pressed. I converted it from the original MySQL code to PDO, but in doing so I fear I misread something and messed up. I'm just wondering if this is a "secure" method of doing this or if I should be using MySQLI and the like. </p>

<p>Below is my script, if you can help me get it working that would be great, but I am more interested in the correct and proper way to delete a row in PHP/PDO.   </p>

<pre><code> &lt;?php
    $dbh = connectDb(); 

    if( isset($_POST['delete']) )
    {
        if( isset( $_POST['id'] ) &amp;&amp; is_numeric( $_POST['id'] ) &amp;&amp; $_POST['id'] &gt; 0 )
        {
            $id = $_POST['id'];
            $stmt = $dbh-&gt;prepare( "DELETE FROM stats WHERE id =:id" );
            $stmt-&gt;bindParam(':id', $id);
            $stmt-&gt;execute();
        }
        else
        {
            echo "Invalid ID";
        }
    }
    $stmt = $dbh-&gt;query('SELECT * FROM news ORDER BY id ASC');

    while($stmt = $rows-&gt;fetch(PDO::FETCH_ASSOC)) {
        echo &lt;&lt;&lt;_END
        &lt;pre&gt;
        Id: {$rows['id']}
        Title: {$rows['title']}
        Body: {$rows['body']}
        Date: {$rows['date']}
        &lt;/pre&gt;
        &lt;form action="rmposts.php" method="post"&gt;
        &lt;input type="hidden" name="delete" value="yes" /&gt;
        &lt;input type="hidden" name="id" value="{$rows['id']}" /&gt;
        &lt;input type="submit" name="delete" value="DELETE NEWS" /&gt;&lt;/form&gt;
    _END;
    }
    ?&gt;
</code></pre>