Senin, 19 Agustus 2013

RINGKASAN BELAJAR PHP

Tabel Sql :

create table if not exists `latihanprasidang` (
`id`int(12)not null auto_increment,
`nama`varchar(15)not null,
`alamat`varchar(15)not null,
`kodepos`int(5)not null,
primary key(`id`));

Index.php
<form action=input.php method=POST>
nama:<input type=text name=nama><br>
alamat:<input type=text name=alamat><br>
kode POS: <input type=text name=kodepos><br>
<input type=sumit name=goes value=simpan>



Tampil.php

<table border=1>
<tr><td>no</td><td>nama</td><td>alamat</td><td>kodepos</td><td>edit</td><td>hapus</td></tr>
<?php
include "koneksi.php";
$m=mysql_query("select * from latihanprasidang");
$no=1;
while($w=mysql_fetch_array($m)){
echo"<tr><td>$no</td>
<td>$w[nama]</td>
<td>$w[alamat]</td>
<td>$w[kodepos]</td>
<td><a href=edit.php?id=$w[id]>edit</a></td><td><a href=hapus.php?id=$w[id]>hapus</a></td>
</tr>";
$no++;
}
?>
</table>


Edit.php
<?php
include "koneksi.php";
$id = $_GET['id'];
$edit = mysql_query("SELECT * FROM latihanprasidang WHERE id='$id'");
$r = mysql_fetch_array($edit);
?>

<form method="post" action="update.php">
<input type=hidden name=id value="<?php echo $id;?>">
  <table border="1">
    <tr>
      <td>EDIT</td>
    </tr>
    <tr>
      <td>nama</td>
      <td><input name="nama" type="text" value="<?php echo $r['nama'];?>" /></td>
    </tr>
        <tr>
      <td>Alamat</td><td>        <input name="alamat" type="text" value="<?php echo $r['alamat'];?>" /></td>
    </tr>
<tr><td>kode pos</td><td><input type=text name=kodepos value="<?php echo $r['kodepos'];?>"></td>
</tr></table>
<input type=submit name=submit value=update>

Update.php
<?php 
include "koneksi.php"; 

mysql_query("update latihanprasidang set 
nama='$_POST[nama]', alamat='$_POST[alamat]', 
kodepos='$_POST[kodepos]' where id='$_POST[id]'"); 

header('location:latihanpra.php'); 

?>

hapus.php

<?php
include "koneksi.php";
mysql_query("delete from latihanprasidang where id='$_GET[id]'");
header("location:latihanpra.php");
?>

Koneksi.php
<?php
mysql_connect("localhost","root","1");
mysql_select_db("latihanpra2");
?>
- See more at: http://miswanphp.blogspot.com/2013/01/membuat-inputtampiledit-dan-hapus.html#sthash.A7luUAS7.dpuf

Tidak ada komentar :

Posting Komentar