Php Code Delete Data from Database - Php

How to delete data from database using PHP code?

Snippet Code


  
Rate this page :
  [ 0 votes]

The DELETE statement helps you to delete records from a database. The following code is used to delete the record with id=7 in the "usertable" table.

<?php $link = mysql_connect("localhost", "root", ""); $conn=mysql_select_db('test_db',$link); $query = "DELETE FROM usertable WHERE id=7"; $result = mysql_query($query); if ($result) { echo "Record deleted successfully"; } else { echo "Error deleting record: " . mysql_error(); } mysql_close(); ?>

Tags


Ask Questions

Ask Question