
- Learn MySQL
- MySQL - Home
- MySQL - Introduction
- MySQL - Installation
- MySQL - Administration
- MySQL - PHP Syntax
- MySQL - Connection
- MySQL - Create Database
- MySQL - Drop Database
- MySQL - Select Database
- MySQL - Data Types
- MySQL - Create Tables
- MySQL - Drop Tables
- MySQL - Insert Query
- MySQL - Select Query
- MySQL - Where Clause
- MySQL - Update Query
- MySQL - Delete Query
- MySQL - Like Clause
- MySQL - Sorting Results
- MySQL - Using Join
- MySQL - NULL Values
- MySQL - Regexps
- MySQL - Transactions
- MySQL - Alter Command
- MySQL - Indexes
- MySQL - Temporary Tables
- MySQL - Clone Tables
- MySQL - Database Info
- MySQL - Using Sequences
- MySQL - Handling Duplicates
- MySQL - SQL Injection
- MySQL - Database Export
- MySQL - Database Import
How to write PHP script to delete data from an existing MySQL table?
We can use the SQL DELETE command with or without the WHERE CLAUSE into the PHP function – mysql_query(). This function will execute the SQL command in a similar way it is executed at the mysql> prompt. To illustrate it we are having the following example −
Example
In this example, we are writing a PHP script to delete a record from MySQL table named ‘tutorial_tbl’ whose tutorial_id as 3.
<?php $dbhost = 'localhost:3036'; $dbuser = 'root'; $dbpass = 'rootpassword'; $conn = mysql_connect($dbhost, $dbuser, $dbpass); if(! $conn ) { die('Could not connect: ' . mysql_error()); } $sql = 'DELETE FROM tutorials_tbl WHERE tutorial_id=3'; mysql_select_db('TUTORIALS'); $retval = mysql_query( $sql, $conn ); if(! $retval ) { die('Could not delete data: ' . mysql_error()); } echo "Deleted data successfully
"; mysql_close($conn); ?>
- Related Articles
- How to write PHP script to update an existing MySQL table?
- How can we delete an existing MySQL table by using PHP script?
- Which PHP functions are used in the PHP script to fetch data from an existing MySQL table?
- How can we insert data into an existing MySQL table by using PHP script?
- How to write PHP script to fetch data, based on some conditions, from MySQL table?
- Which PHP function is used to delete an existing MySQL table?
- How to write PHP script by using LIKE clause inside it to match the data from MySQL table?
- Which PHP function is used to insert data into an existing MySQL table?
- How to write PHP script by using ORDER BY clause inside it to sort the data of MySQL table?
- Create MySQL query to create a table from an existing table?
- Write an example to establish MySQL database connection using PHP script?
- How to add columns to an existing MySQL table?
- How to delete a column from an existing table in a database using JDBC API?
- Which PHP function is used to delete an existing database?
- How to add current date to an existing MySQL table?

Advertisements