Question


Sumit

how to delete record in database using php ?

Date = 2015-03-23

Comments by experts


Rajesh Kakadiya
2015-03-23

// check this solution for you

<html>
<body>
<?php
$con
=mysql_connect("localhost","username","password"); // connection to localhost
if(!$con)
  {
  die(
'Could not connect :'.mysql_error()); // showing error if having problem with username or password
  
}
mysql_select_db("database_name",$con); // select database from localhost
 
$id=$_POST['id'];
$sql="DELETE FROM table_name WHERE id='$id'";  // Delete specific record from table
 
if(!mysql_query($sql,$con)) 
  {
  die(
'Error in inserting record :'.mysql_error());  // if problem with tablename or any field name
  
}
echo 
"record deleted"// record Deleted successfully
mysql_close($con// close connection to server
?>
</body>
</html>
DesignStudio
2015-03-23

This has been helpful to me.


Type your Comment below and click to send comment