Home > Backend Development > PHP Tutorial > php delete data in mysql table

php delete data in mysql table

巴扎黑
Release: 2016-11-23 10:43:56
Original
1045 people have browsed it

php delete data in mysql table

<html>
<head>
<title>Delete a Record from MySQL Database</title>
</head>
<body>
<?php
if(isset($_POST[&#39;delete&#39;]))
{
$dbhost = &#39;localhost:3306&#39;;
$dbuser = &#39;root&#39;;
$dbpass = &#39;root&#39;;
$conn = mysql_connect($dbhost, $dbuser, $dbpass);
if(! $conn )
{
 die(&#39;Could not connect &#39;);
}
$emp_id = $_POST[&#39;emp_id&#39;];
$sql = "DELETE from employee ".
  "WHERE emp_id = $emp_id" ;
print "sql" . $sql;   
mysql_select_db(&#39;test_db&#39;);
$retval = mysql_query( $sql, $conn );
if(! $retval )
{
 die(&#39;Could not delete data&#39;);
}
echo "Deleted data successfully\n";
mysql_close($conn);
}
else
{
?>
<form method="post" action="<?php $_PHP_SELF ?>">
<table width="400" border="0" cellspacing="1" cellpadding="2">
<tr>
<td width="100">Employee ID</td>
<td><input name="emp_id" type="text" id="emp_id"></td>
</tr>
<tr>
<td width="100"> </td>
<td> </td>
</tr>
<tr>
<td width="100"> </td>
<td>
<input name="delete" type="submit" id="delete" value="Delete">
</td>
</tr>
</table>
</form>
<?php
}
?>
</body>
</html>
Copy after login


Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template