AMSSOI-Andhra Mahila Sabha School of Informatics
AMSSOI-Andhra Mahila Sabha School of Informatics

AMSSOI-Andhra Mahila Sabha School of Informatics

Lesson 21 Delete data from database in PHP for AMSSOI Hyderabad
Por Rashmi Prasad Bhat
Lesson 21 Delete data from database in PHP for AMSSOI Hyderabad

Lesson 21: Delete data from database

In the two previous lessons, you have learned to insert and retrieve data from a database. In this lesson, we'll look at how to delete records in the database, which is considerably easier than inserting data.

Delete data using SQL

The syntax for an SQL statement that deletes records is:


DELETE FROM TableName WHERE condition


Example: Delete a record

When deleting a record, you can use the unique AutoNumber field in the database. In our database, it is the column named id. Using this unique identifier ensures that you only delete one record. In the next example, we delete the record where id has the value 24:


<html>
<head>
<title>Delete data in the database</title>
</head>

<body>

<?php
// Connect to database server
mysql_connect("mysql.myhost.com", "user", "sesame") or die (mysql_error ());

// Select database
mysql_select_db("mydatabase") or die(mysql_error());

// The SQL statement that deletes the record
$strSQL = "DELETE FROM people WHERE id = 24";
mysql_query($strSQL);

// Close the database connection
mysql_close();
?>

<h1>Record is deleted!</h1>

</body>
</html>


Remember that there is no "Recycle Bin" when working with databases and PHP. Once you have deleted a record, it is gone and cannot be restored.

Comentarios

Actualícenme sobre este comentario
Publicar ahora
Compartir sus materiales universitarios y notas de estudio
Noticias y eventos de la universidad
  • Material de estudio
    Colegios que comparten notas de conferencias, archivos y material informativo relevante.
    Material de estudio
  • Videos educativos
    Videos de práctica o conocimientos específicos, realizado por y para estudiantes
    Videos educativos
  • Conferencia PPT's
    Los estudiantes comparten PPTs de distintos cursos y asignaturas para auxiliar a otros compañeros
    Conferencia PPT's
  • Preguntar y aclarar dudas
    Una base educativa, que engloba preguntas generales como específicas de distintos temas, todo esto alimentado por los mejores alumnos.
    Preguntar y aclarar dudas
Actualización de información por parte de los estudiantes de la respectiva universidad