PHP Delete Data from Database

Google Advertisements

Prev Tutorial Next Tutorial

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 = mysql_connect($server, $user, $pass)
or die("Could not connect to server ... \n" . mysql_error ());

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

?>

delete.html

Delete page

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

mysql_select_db("tutorohx_rw", $conncection);

$valueToSearch = $_POST['valueToSearch'];

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

?>

<?php

if ($result)
 {
  while($row = mysql_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';

mysql_select_db("tutorohx_rw", $conncection);

$s_no = $_POST['s_no'];

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

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

?>

Prev Tutorial Next Tutorial

Google Advertisements

We have more than 5 Groups which have 500000+ Members and some Pages have more than 100000+ members. If you want to post your article on our website/FB Group/FB Page please contact on hitesh.xc@gmail.com or 8076671483

Buy This Ad Space @$50 per Month, Ad Size 600X200 Contact on: hitesh.xc@gmail.com or 8076671483

Path variable is set for providing path for all Java tools like java, javac, javap, javah, jar, appletviewer which are used in java programming. All these tools are available in bin folders so we set path upto bin folders.

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.

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

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

Download Projects

Adsense Advertisements


Buy This ads Space 8076671483

Buy This Ad Space @$120 per Month, Ad Size 300X600 Contact on: hitesh.xc@gmail.com or 8076671483