saftutorials.com

HTML

How to download HTMl Editors

How to use HTML tags

How to Comment in HTML

How to create an HTML link

How to link to a specific part of a page HTML

How to Insert Images with HTML

How to insert audio in HTML

How to insert videos in HTML

How to use Table Tag in HTML

How to Use HTML List Elements

How to use HTML Iframe

How to use HTML Symbols

How to use HTML Color Codes

How to Create HTML From

How to learn HTML

CSS

How to use CSS Background

JS

PHP

How to redirect to another page using PHP

How to get last inserted id in MySQL using PHP

How to learn php

How to insert a row into database by using PHP

How to fetch data from table by using php

How to print table data by using while loop in php

How to perform search operation into database by using php

MySQL

How to create Table in PHP MySQL?

How to Insert Data Into MySQL Database Table Using PHP?

How to Select Data from MySQL Database Tables Using PHP

How to Update data in MySQL Database Table using PHP

How to Delete Data from MySQL using PHP

How to make MySQL query ORDER BY conditions

How to Select LIMIT data in PHP MySQL

SQL

BOOTSTRAP

AJAX

DATATABLE

SEO

EARNING

GOOGLE

FACEBOOK

YOUTUBE

WordPress

How to Install WordPress?

How to use WordPress Dashboard?

How to Install Plugins in WordPress?

How to Customize WordPress Plugins?

How to Change General Settings in WordPress?

How to Change Writing Settings in WordPress

How to Setup the Reading Settings in WordPress

How to Setup the Discussion Settings in WordPress

How to Setup the Media Settings in WordPress

How to Setup the Permalink Settings in WordPress

How to Setup the Plugin Settings in WordPress

How to Add Categories to WordPress

How to Edit Category in WordPress

How to Delete Category in WordPress

How to Arrange Category in WordPress

How to Add a new Post in WordPress

How to Edit Post in WordPress

How to Delete Post in WordPress

How to Review Post in WordPress

How to add Media in WordPress

How to Edit Media in WordPress

How to add a Page in WordPress

How to Delete Media in WordPress

How to Add Page in WordPress

How to Edit Pages in WordPress

How to Learn WordPress

How to Delete Page in WordPress

How to add New Tag in WordPress

How to Edit Tags in WordPress

How to Delete Tags in WordPress

How to Delete Data from MySQL using PHP

Answer: Create the MySQL query for deleting a row from the table and then execute it with mysql_query() function. We can delete a row from the table by using MYSQL DELETE statement.


Syntax of MYSQL DELETE statement

DELETE FROM table_name WHERE some_column=some_value;


Below is a simple example to delete a record from student table.Run this example for better understanding delete operation.

For deleting a row you have to provide student id.

<?php
 $database_host = 'localhost:3036';
 $database_user = 'root';
 $database_pass = '';
 $conn = mysql_connect($database_host, $database_user, $database_pass);
 if(! $conn ) {
   die('Could not connect: ' . mysql_error());
 }else{
   echo 'Connected successfully\n';
}
 $selected_or_not = mysql_select_db( 'xyz_school' );
 if(! $selected_or_not ) {
   die('Not Selected xyz_school database');
 }else{
   echo 'Selected xyz_school database';
}
 $sql = 'DELETE FROM student WHERE student_id = 1';
 $result = mysql_query( $sql, $conn );
 if(! $result ) {
  die('Could not deleted the row: ' . mysql_error());
 }
echo "Deleted successfully";
 mysql_close($conn);
?>
<!DOCTYPE html>
<html>
<body>
    <h2>Student List</h2>
     <table>
        <th>
           <td>Student ID</td>
           <td>Student Name</td>
           <td>Address</td>
           <td>Enrollment No</td>
           <td>Joining date</td>
           <td>Action</td>
        </th>
<?php
$i = 1;
while($row = mysql_fetch_array($result)) {
?>
        <tr>
           <td><?php echo $row['student_id'];?> </td>
           <td><?php echo $row['student_name'] ."or". $row[1];?> </td>
           <td><?php echo $row['student_address'] ."or". $row[2];?> </td>
           <td><?php echo $row['student_enrollment_no'] ."or". $row[3];?> </td>
           <td><?php echo $row['join_date'] ."or". $row[4];?> </td>
           <td>Del</td>
        </tr>
<?php
}
?>
     </table>
  </body>
</html>

IDStudent NameAddressEnrollment NoJoining DateAction
1JohnCalifornia1010/02/2017Del
2JakobNew York2020/05/2017Del
Now you can link your delete page with Del when Delete successful then page redirects automatically your current page. 

Learn PHP Redirects
Multiple Data Delete
You can delete multiple data from MySQL Database. Just only one step for this. For delete multiple data from database you should not define only one student id like student id = 1, but you should define a value which you want to delete: 
Example 
$sql = 'DELETE FROM student WHERE city = California '; // In this Query delete all your record where city California. So be careful with this operation.

Find us on

Facebook Google Plus Twitter Pinterest YouTube

web statistic