Wednesday, February 28, 2007

Delete Database fields...

Creating is very important, but sometimes you also need to delete. So, let's say you need to delete a certain place in the database. A field containing a user name for example. The function you are supposed to use is the mysql_query(); function in PHP.
So let's say that the table we are using is named users and this table contains the fields: ID, user_name, password and email.
In order to delete the correct value, we need to know the ID value of the user_name that we want to delete, because it's a unique value.
This is the function:

mysql_query("DELETE FROM `users` WHERE `ID`='2' ");

Right now, ID, user_name, password and email is completely deleted from the database.
This is a very easy example for beginners.
In later posts I will show you more complex examples where you can use PHP variables extracted from the database or set by you etc....
Enjoy.

No comments: