Mysql Tutorial – delete data from table
Hello Friends,
If you are a learner (new) in PHP / Mysql and don’t know how to delete data from table in Mysql database from php file than Here is the easiest and error-free way to delete data from table in Mysql database.
You can delete data using DELETE query .
If you will not specify the particular id for deleting record than it will delete all records from that table.
<?php
///*** This file will help you to delete data from tables in MYSQL database using PHP – Rakshit Patel **////include(“mysql-connection.php”);
mysql_select_db(“testing”); // select database
$sql = “DELETE FROM test_table WHERE id = ’1′ “;
// $sql = “DELETE FROM test_table”; this will delete all data from table test_table
mysql_query($sql) or die(‘Error, delete query failed’);
include(“mysql-connection-close.php”);
?>
Here first i have added mysql-connection.php file which will make connection with Mysql database. If you dont know how to make connection with Mysql database than click here.
Now i have selected Mysql database (named testing ). if you have not created database than click here.
After selecting database , you need to execute the query as written above to delete record from table. If you have not created table yet , than click here.
Thats it. Just check the record you have deleted by using Select Query.
At last i have included mysql-connection-close.php file.
<?php ///*** This file will close MYSQL connection using PHP – Rakshit Patel **////
mysql_close($connection); // close mysql connection
?>
This is nothing but it will close connection which we have made earlier. Its not necessary but a sign of Good Programmer.
Cheers !!
No related posts.
| Print article | This entry was posted by Rakshit Patel on March 10, 2009 at 1:29 am, and is filed under Mysql, PHP, Programming. Follow any responses to this post through RSS 2.0. You can leave a response or trackback from your own site. |

I am
I am Shail Patel studing in MCA and working as PHP developer(Part time) in ahmedabad. I was looking forward to share my internet ideas to people of this beautiful world. I found this site as an ideal one to do this. Now i am author of this site and i hope my articles will be helpful to you guys.