www.pickatutorial.com Computer Tutorials
Top Tutorials: C/C++ | C#.NET | PHP MySQL | Java | Java Script | jQuery | HTML | xHTML | HTML5 | VB Script| CSS
Lessons PHP MySQL DELETE Bookmark and Share
Lesson 1
Lesson 2
Lesson 3
Lesson 4
Lesson 5
Lesson 6
Lesson 7
Lesson 8
Lesson 9
Lesson 10
Lesson 11
Lesson 12
Lesson 13
Lesson 14
Lesson 15
Lesson 16
Lesson 17
Lesson 18
Lesson 19
Lesson 20
Lesson 21
Lesson 22
Lesson 23
Lesson 24
Lesson 25
Lesson 26
Lesson 27
Lesson 28
Lesson 29
Lesson 30
Lesson 31
Lesson 32
Lesson 33
Lesson 34
Lesson 35
Lesson 36
Lesson 37
Lesson 38
Lesson 39
Lesson 40
Lesson 41
Lesson 42
Lesson 43
Lesson 44
The DELETE statement is used to delete records from a database table. Actually we use DELETE FROM statement to delete records from a database table. Let's see its syntax:

DELETE FROM table_name
WHERE some_column = some_value


Notice the use of WHERE clause in the DELETE syntax above. The WHERE clause specifies which record or records should be deleted. If you omit the WHERE clause, all records from the table would be deleted!

Just like other SQL statements / commands, we need to use the PHP function mysql_query() to execute the above statement. Let's see an example:

Example
Considerr the following "Students" table:
Name Age Address
Adam 20 Adam's Address
Jacob 18 Jacob's Address
Danial 19 Danial's Address
The following code deletes all the records in the "Students" table where Name='Jacob':

<?php
$con = mysql_connect("localhost", "adam","ada");
if (!$con)
{
die('Error connecting database');
}
mysql_select_db("my_db", $con);
mysql_query("DELETE FROM Students WHERE Name='Jacob'");
mysql_close($con);
?>


Table "Student" after the deletion:
Name Age Address
Adam 20 Adam's Address
Danial 19 Danial's Address



Home - Advertise - Contact - Disclaimer - About Us
© Since 2006 pickatutorial.com -- All Rights Reserved.