Delete records from MySQL database is an easily SQL command. You need to put the key value just as id, name or others into this command. This tutorial use the file select.php from Update Record tutorial and make a new file delete.php.
delete from table_name where column_name='value'
This tutorail need 2 files.
1. select.php from Update Record tutorial.
In this file, you have to put some codes for a new link. This link will send GET method parameter to delete.php.
// Connect database
// Get all records in all columns from table and put it in $result.
$result=mysql_query("select * from phonebook");
/*Split records in $result by table rows and put them in $row.
Make it looping by while statement. */
echo "ID : $row['id']
echo "Name : $row['name']
echo "Email : $row['email']
echo "Tel : $row['tel']
// Add a link with a parameter(id) and it's value. This for update record at update.php
// Add a link with a parameter(id) and it's value. This for delete record at delete.php
Browse "select.php" by go to http://localhost/select.php.
Result : (Links below are NOT real on this page)
ID : 1
Name : Jack
Email : firstname.lastname@example.org
Tel : 12345678
Delete <- when you mouse over this. It will show "http://localhost/delete.php?id=1"in your browser's status bar.
ID : 2
Name : Joe
Email : email@example.com
Tel : 87654321
Delete <- when you mouse over this. It will show "http://localhost/delete.php?id=2" in your browser's status bar.
The values are the same as ID parameters. When you click on these links, the page will change to delete.php.
This file will get parameter($id) from select.php and delete the record where id column equal in $id .
// Connect database.
// Get values from form.
// Do delete statement.
mysql_query("delete from phonebook where id='$id'");
// Close database connection
// Redirect to select.php.
Browse select.php on your web browser as http://localhost/select.php and click on "Delete" link. This page will go to delete.php with id record and delete.php will delete this record and re-direct back to select.php immediately.
Put Ebay RSS Feeds onto your website
SEO Elite Software
Domain Dashboard CPanel & Seo Manager
Work at Home Ideas and Opportunities
• Introduction & Get Start
• Using Form
PHP Control Structures
Create Database & Table