Delete / Remove Records In Database Table: PHP & MySQL

Video tutorial demonstrates deleting / removing of data / records from the database table.

First look at these short videos:
Connect to the database
Simple / basic insertion operation
Insertion of Records into Database using Forms: PHP & MySQL (important)
SELECT / LIST Records From Database Table: PHP & MySQL
UPDATE / EDIT Records In Database Table: PHP & MySQL

SELECTING and Displaying Data
index.php

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
< ?php
include_once('db.php');
 
if(isset($_POST['name']))
{
  $name = $_POST['name'];
 
  if(mysql_query("INSERT INTO apple VALUES('','$name')"))
echo "Successful Insertion!";
  else
echo "Please try again";
}
 
 
$res = mysql_query("SELECT * FROM apple");
 
 
?>
<html>
<head>
 
<style type="text/css">
 li { list-style-type: none; display: inline; padding: 10px; text-align: center;}
// li:hover { background-color: yellow; }
</style>
 
</head>
<body>
<form action="." method="POST">
Name: <input type="text" name="name"/><br />
<input type="submit" value=" Enter "/>
</form>
 
<h1>List of companies ..</h1>
<ul>
< ?php
while( $row = mysql_fetch_array($res) )
  echo "<li>$row[id]. <li>$row[name]</li> 
                <li><a href='edit.php?edit=$row[id]'>edit</a></li>
                <li><a href='delete.php?del=$row[id]'>delete</a></li><br />";
?>
</ul>
</body>
</html>

Some CSS styling for simple / basic presentation: CSS Hover Over Effect

We have added delete link beside each record.

Deleting Records From Database Table

1
2
3
4
5
6
7
8
9
10
11
< ?php
include_once('db.php');
 
if( isset($_GET['del']) )
{
$id = $_GET['del'];
$sql= "DELETE FROM apple WHERE id='$id'";
$res= mysql_query($sql) or die("Failed".mysql_error());
echo "<meta http-equiv='refresh' content='0;url=index.php'>";
}
?>

Here we receive the value of id, passed from index.php and assign it to a local variable called $id.
Then using simple DELETE query, we delete the records associated with the id.

Video Tutorial: Delete / Remove Records In Database Table: PHP & MySQL


[youtube https://www.youtube.com/watch?v=ByaECx2mj9M]

YouTube Link: https://www.youtube.com/watch?v=ByaECx2mj9M [Watch the Video In Full Screen.]



List of companies ..
1. Google USA edit delete
2. Apple USA edit delete
3. Microsoft USA edit delete
4. Oracle USA edit delete