anantamu.com
PHP - Introduction
PHP - Setup
PHP - Syntax
PHP - String
PHP - constants
PHP - Operators
PHP - Superglobals
PHP Forms PHP - Forms
MySQL
MySQL - Create DB
MySQL - Update Data
MySQL - Delete Data


PHP MySQL DETELE statement


The DETELE statement is used to delete data from table


DETELE STATEMENT

DETELE FROM tableName WHERE columnName=value

Displaying the records and action of delete from Profile table.

<?php
$servername = "localhost";
$username1 = "root";
$password1 = "";
$dbname = "sample";
//server connection
$connection = mysqli_connect($servername, $username1, $password1, $dbname);
if (!$connection) {
die("Connection failed: " . mysqli_connect_error());
}
$sqlQuery='select * from profile';


$resultSql=mysqli_query($connection, $sqlQuery);
echo '<table>';
echo '<tr><td>Name</td><td>Address</td><td>Action</td></tr>';

if (@mysqli_num_rows(@$resultSql) >= 1) {
// output data of each row
  while ($rowValue = mysqli_fetch_assoc($resultSql)) {
	  echo '<tr>';
	  echo '<td>'.$rowValue['Name'].'</td>';
	  echo  '<td>'.$rowValue['Address'].'</td>';
	  echo  '<td>'."<a href=profileDelete.php?id=".$rowValue['id'].">Delete</a>".'</td>';
	  echo '</tr>';

  }
}else{	
	echo '<tr><td>no records found</td><td></td></tr>';
}
echo '</table>';
mysqli_close($connection);
?> 
                    

When user click the delete then it goes to this page profileDelete.php and action will perform.


Detele the profile details: profileDelete.php file

<?php
$servername = "localhost";
$username1 = "root";
$password1 = "";
$dbname = "sample";
//server connection
$connection = mysqli_connect($servername, $username1, $password1, $dbname);
if (!$connection) {
die("Connection failed: " . mysqli_connect_error());
}
$sqlQuery="delete from  profile  WHERE id = '" . $_GET['id'] . "' ";


$resultSql=mysqli_query($connection, $sqlQuery);

mysqli_close($connection);
header("location:".$_SERVER['HTTP_REFERER']."");
?> 
                    

School