Hi… welcome in my blog… In here you want getting many IT
knowledge..
Now.. I want giving you IT knowledge about PHP and discuss
of “DELETE DATABASE IN PHP”.
Previous I was giving tutorial about “INPUT and EDIT
DATABASE IN PHP”.
Ok … direcrt to go !!
For deleting database in PHP we are need4 (four) components..
they are is :
1. DATABASE
2. FILE CONNECTION.PHP
3. FILE DISPLAY.PHP
4. FILE ACTION.PHP
We are start from DATABASE until FILE ACTION.PHP
1. DATABASE
I was giving tutorial about database if you do not know please
visit in
http://have-fun-and-enjoy.blogspot.com/2012/07/create-database-and-table-in-mysql.html
2. FILE CONNECTION.PHP
http://have-fun-and-enjoy.blogspot.com/2012/08/connection-in-php.html
3. FILE DISPLAY.PHP
In making file display.php likely file display.php for edit…
but action of edit I change with action of delete…
Ok.. you can copy this coding and paste in your notepad
<html>
<head>
<title></title>
<head>
<body>
<?php
include "connection.php";
$aksi="action.php";
switch($_GET[act])
{
default:
echo "<table border=1 <tr> <th> ID MHS
</th> <th> NAME MHS </th> <th> SEX MHS </th>
<th> DATE MHS </th> <th> ADDRESS </th> <th>
ACTION </th> </tr>";
$a = "select * from adsanse";
$b = mysql_query($a);
while ($r = mysql_fetch_array($b))
{
$id = $r[id];
$name = $r[name];
$sex = $r[sex];
$born
= $r[born];
$address = $r[address];
echo "<tr> <td align = center> $id
</td> <td> $name </td> <td> $sex </td> <td>
$born </td> <td> $address </td>
<td align = center> <a
href='$aksi?module=product&act=delete&id=$r[id]'> delete
</a></td>
</tr>";
}
break;
}
?>
</table>
</body>
</html>
If it is save with save astype “PHP” and give name “select.php”.
4. FILE ACTION.PHP
This file for processing… you can copy this coding and paste
to notepad
<?php
include "connection.php";
$module=$_GET[module];
$act=$_GET[act];
if ($module=='product' AND $act=='delete')
{
$a = $_POST[year].'-'.$_POST[moon].'-'.$_POST[day];
mysql_query("DELETE
from adsanse where id = '$_GET[id]'");
}
else
{
echo "failed";
}
?>
DON’T forget give name “action.php”… if not this file not
exist…
NOTE : :
Give name of second file “action.php”.
If you using copy and paste you must change all quotes (“ “)
or (‘ ‘)
for working you must open XAMPP and trun on “apache”, and “mysql”.
for working you must open XAMPP and trun on “apache”, and “mysql”.
Open your browser and write “localhost/select.php” >>
enter
Ok.. just for it..
I hope you understand with my article…
See you later..
No comments:
Post a Comment