PHP Delete Data from Database

Google Advertisements

Search Record in database using PHP PHP MySQL Order By

Delete Data from Database in PHP

To delete any record from database on webpage first you need to create user interface so here i am going to create Html page and search box. First search record from database if it present then record will delete. To delete any record from database we use below MYSQL query.

Syntax

delete from table_name where id=2;

connect-db.php

Connect to database

<?php

$server = 'localhost';
$user = 'user_name';
$pass = 'password';
$db = 'database_name';

// Connect to Database

$connection = mysqli_connect($server, $user, $pass)
or die("Could not connect to server ... \n" . mysqli_error ());

// select database
mysqli_select_db($db)
or die("Could not connect to database ... \n" . mysqli_error ());

?>

delete.html

Delete page

<?php
include 'db-connect.php';

mysqli_select_db("tutorohx_rw", $conncection);

$valueToSearch = $_POST['valueToSearch'];

$sql = "SELECT * FROM letter_dispatch WHERE s_no=$valueToSearch";
$result = mysqli_query($sql, $connection);

?>

<?php

if ($result)
 {
  while($row = mysqli_fetch_array($result))
 {
?>

// Show Record

<h3>You Want to Delere Record:</h3>
<table class="table" border='0'>
<form method="post" action='delete-record-successfully.php' id="deleteform">
<tr><th>Serial no</th><td><span style="color:red; font-weight: bold; font-size:20px;"><?php echo $valueToSearch;?></span></td></tr>
<tr><th></th><td><input type=hidden name=s_no value=<?php echo $row['s_no']; ?>></td></tr>
<tr><td><input type="submit" form="deleteform" value="Delete"></td></tr>
</form>

<?php
 }
} 
?>
</table>

delete-record-successfully.php

Record Deleted

<?php

include 'db-connect.php';

mysqli_select_db("tutorohx_rw", $conncection);

$s_no = $_POST['s_no'];

$sql = "DELETE FROM letter_dispatch where s_no='$s_no'";

$result = mysqli_query($sql, $connection);
if($result)
{
 echo"Record Deleted Successfully........";
}
else
{
 echo"Try Again........";
}

?>

Search Record in database using PHP PHP MySQL Order By

Google Advertisements

We have more than 5 Groups which have 500000+ Members and some Pages have more than 100000+ members. For Advertisement contact on [email protected] or 8076671483

Buy This Ad Space @$50 per Month, Ad Size 600X200 Contact on: [email protected] or 8076671483

Pure VPN Privide Lowest Price VPN Just @ $1.65. Per Month with Non Detected IP Lowest Price Non Detected IP VPN

Classpath variable is set for providing a path for predefined Java classes which is used in our application. All classes are available in lib/rt.jar so we set classpath upto lib/rt.jar. Difference between path and classpath in Java

Cloud computing is the on demand availability of computer system resources, especially data storage and computing power, without direct active management by the user. Cloud Computing Tutorial

College Projects Related to Java, AWT, C Projects for College, C++ Projects for College, Android Projects. Download Java C C++ Projects

Download Projects

Adsense Advertisements


Buy This ads Space 8076671483

Buy This Ad Space @$120 per Month, Ad Size 300X600 Contact on: [email protected] or 8076671483 Try this Keyword C++ Programs