Hi… welcome to my blog…
In here you
want getting many IT knowledge, like as : PHP, MYSQL, HTML, and other knowledge…
Previous I was giving tutorial about
PHP and explain of “input database from php” and “display database with PHP”…
Now I want givingyou tutorial PHP
about “EDIT DATABASE IN PHP”…
You ready… ?? if yes.. let’s read this
article…
For edit database in PHP we need 4 (four)
component.. they are :
1. DATABASE
2. FILE CONNECTION.PHP
3. FILE DISPLAY.PHP
4. FILE ACTION.PHP
Ok ,,, we are start from making
database until making file action.php
1. DATABASE
Database is place for saving datas, like as : name, born,
address, and other. We can input variable integer, character, or date… we also
cana inputting primary key and auto_increment
I was disscus about it.. if you do not know you can visit in
2. FILE CONNECTION
File conection include “localhost”, “root”, “pass”, “database”.
For more complate please
visit in
http://have-fun-and-enjoy.blogspot.com/2012/08/connection-in-php.html
http://have-fun-and-enjoy.blogspot.com/2012/08/connection-in-php.html
3. FILE DISPLAY
You can copy and paste this coding in
your notepad
<html>
<head>
<title></title>
<head>
<body>
<?php
include "koneksi.php";
$aksi="action.php";
switch($_GET[act]){
default:
echo "<table border=1> <tr> <th> ID MHS </th>
<th>NAMA 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>
<a href=?module=product&act=editproduk&id=$r[id]>Edit</a>
</tr>";
}
break;
case "editproduk":
$edit =
mysql_query("SELECT * FROM adsanse WHERE id='$_GET[id]'");
$r = mysql_fetch_array($edit);
echo "<h2>Edit PRODUCT</h2>
<form
method=POST enctype='multipart/form-data' action=$aksi module=product&act=update>
<input type=hidden name='id'
value='$r[id]'>
<table>
<tr><td
width=70>Name MHS</td>
<td> : <input type=text name=name size=60
value='$r[name]'></td></tr>
<tr><td width=70>sex </td> <td> : <input type=radio name=sex
size=60 value=MAN>MAN<input type=radio name=sex size=60
value=WOMAN>WOMAN</td></tr>
<tr><td
width=70>date</td>
<td> :
<select name=year>
<option value = 0 >-/-</option>
<option value =
1990>1990</option>
<option value =
1991>1991</option>
<option value =
1992>1992</option>
<option value =
1993>1993</option>
<option value =
1994>1994</option>
</select>
<select name=moon>
<option value = 01>jan</option>
<option value = 02>feb</option>
<option value = 03>mar</option>
<option value = 05>mei</option>
</select>
</select>
<select name=day>
<option value = 01>01</option>
<option value = 02>02</option>
<option value = 03>03</option>
<option value = 04>04</option>
<option value = 05>05</option>
</select>
</td></tr>
<tr><td
width=70>address</td>
<td> : <textarea name=address cols = 14 rows = 3
> $r[address] </textarea></td></tr>
<tr><td colspan=2><input
type=submit value=Update>
<input type=button value=Batal
OnClick=self.history.back()></td></tr>
</table></form>";
break;
}
?>
</table>
</body>
</html>
Give name = select.PHP…
4. FILE ACTION.PHP
You can too copy this file and paste
in your notepad….
<?php
include "koneksi.php";
$module=$_GET[module];
$act=$_GET[act];
if ($module=='product' AND
$act=='update')
{
$a =
$_POST[year].'-'.$_POST[moon].'-'.$_POST[day];
mysql_query("UPDATE
adsanse SET name = '$_POST[name]', sex =
'$_POST[sex]', born = '$a', address = '$_POST[address]' WHERE
id = '$_POST[id]'") ;
}
else
{
echo "failed";
}
?>
DON’T FORGET… GIVE name = “action.php”
NOTE ::
IF you using copy and paste… please change all quotes ( “ “ ) or ( ‘ ‘ ).
For execution trun on xampp and start “apache”
and “mysql”
OK just it …
I hope you understand with this all…
See you later
No comments:
Post a Comment