PHP MySQL Delete Table
From w3cyberlearnings
Contents |
PHP MySQL Delete Record
Delete a record uses DELETE statement. You need to specifies the record that you want to delete.
Syntax
$delete_table = 'DELETE FROM student WHERE student_id=5'; mysql_query($delete_table, $connection);
Example 1
<?php define('HOST', 'localhost'); define('USER', 'root'); define('PASS', 'yeething'); define('DBNAME', 'woowood'); $connection = mysql_connect(HOST, USER, PASS); if (!$connection) { die("can not connect to the server!<br/>"); } else { $rdb = mysql_select_db(DBNAME); if (!$rdb) { die("The " . DBNAME . "database could not be selected"); } else { // student table $delete_table = 'DELETE FROM student WHERE student_id=5'; if (!mysql_query($delete_table, $connection)) { echo "Can't delete table: " . mysql_error($connection) . "<br/>"; } else { echo "You have successfully delete table. <br/>"; } } } mysql_close($connection); ?>
Output
You have successfully delete table.
Example 2
Delete record for first name="abc" and last_name="bcd".
DELETE FROM student where first_name="abc" AND last_name="bcd";