[Solved] How to add a button to my PHP form that deletes rows from my MYSQL database [duplicate]


In your html view page some change echo "<td><a href="https://stackoverflow.com/questions/40479421/delete.php?did=".$row["id']."'>Delete</a></td>"; like bellow:

<?php
while($row = mysql_fetch_array($result))
{
    echo "<tr>";
        echo "<td>" . $row['name'] . "</td>";
        echo "<td>" . $row['id'] . "</td>";
        echo "<td>" . $row['rollnumber'] . "</td>";
        echo "<td>" . $row['address'] . "</td>";
        echo "<td>" . $row['phonenumber'] . "</td>";
        echo "<td><a href="https://stackoverflow.com/questions/40479421/delete.php?did=".$row["id']."'>Delete</a></td>";
    echo "</tr>";
}
?>

PHP delete code :

<?php
if(isset($_GET['did'])) {
    $delete_id = mysql_real_escape_string($_GET['did']);
    $sql = mysql_query("DELETE FROM venu WHERE id = '".$delete_id."'");
    if($sql) {
        echo "<br/><br/><span>deleted successfully...!!</span>";
    } else {
        echo "ERROR";
    }
}
?>

Note : Please avoid mysql_* because mysql_* has beed removed from
PHP 7. Please use mysqli or PDO.

More details about of PDO connection http://php.net/manual/en/pdo.connections.php

And more details about of mysqli http://php.net/manual/en/mysqli.query.php

2

solved How to add a button to my PHP form that deletes rows from my MYSQL database [duplicate]