Anda di halaman 1dari 11

Tutorial input,tampil,edit dan delete Menggunakan PHP dan mysql (xampp) (Tutorial php)

Oleh Muhamad ALI

13

Selamat sore sobat internet,kali ini saya akan mencoba membagikan turorial dengan judul seperti diatas,tutorial ini awalnya pas ane pertama kali belajar php dan mysql,ane ambil dan belajar dari embah Google,namun tutorial ini sudah ane modifikasi sedemikian rupa,dengan harapan bisa mempermudah pemahaman kita semua...amin,,, Okehhh tanpa perlu basa basi di intro langsung saja ikutin tutorialnya,,,,yupzzz,,,capcupzzz = Sebelumnya sobat harus bikin file untuk koneksi ke databasenya dulu simpan dan beri nama config.php Ini kodingnya :

<?php mysql_connect("localhost","root",""); mysql_select_db("tutorial"); ?>

1. Langkah Pertama yaitu silakan sobat bikin tabel databasenya dulu seperti gambar dibawah..

www.muhamadali.besaba.com

Page 2

2. Kalo sudah silakan disain cssnya seperti berikut

Desain.css =======================================================

table[border="2"] { font:normal 14px Verdana; color: #990066; } table[border="2"] tr {


www.muhamadali.besaba.com Page 3

background:#F0F0F0; } table[border="2"] th, table[border="2"] td { vertical-align:top; padding:5px 10px; border:2px solid #990066; } table[border="1"] td:nth-child(odd) { background:#DEDEDE; } table[border="2"] th { background:#4A6D67; border-radius: 10px; -moz-border-radius: 10px; -webkit-border-radius: 10px; color:#fff;} Notes : jangan lupa simpan cssnya dengan nama style.css. 3. Langkah berikutnya adalah silakan bikin form inputnya di halaman Index.php ============================ <!DOCTYPE html> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=iso-88591" />

www.muhamadali.besaba.com

Page 4

<title>tutorial1</title> <link rel="stylesheet" type="text/css" href="style.css" /> </head>

<body> <form action=proses.php method=POST> Nama:<input type=text name=nama><br> Kampus:<input type=text name=kampus><br> Nim : <input type=text name=nim><br> <input type=submit name=bagikan value=simpan> </body> </html>

Nah ini file untuk proses.php nya ========================= <?php include "config.php"; $nama= $_POST["nama"]; $kampus= $_POST["kampus"]; $nim= $_POST["nim"];

$input ="insert into torialdua(id,nama,kampus,nim)values(null,'$nama','$kampus ','$nim ')"; $query = mysql_query($input); if (query)


www.muhamadali.besaba.com Page 5

{ echo "<div><pre>Nama:$nama</pre>"; echo "<pre>kampus:$kampus</pre>"; echo "<pre> Nim:$nim</pre><br>"; echo "data di atas telah disimpan<br>"; echo "<a href= ' keliatan.php >lihat data</a>"; } else { echo "gagal tersimpan"; echo "<a href='index.php'>ulangi</a></div>"; }

?>

4. Nah untuk yang ini adalah bagian untuk menampilkan data pada tabel yang ada di database yang barusan dibuat .... Silakan simpan dan Beri nama dengan keliatan.php <!DOCTYPE html> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=iso-88591" /> <title>tampila</title>

www.muhamadali.besaba.com

Page 6

<link rel="stylesheet" type="text/css" href="style.css" /> </head>

<body> <table > <tr><td>no</td><td>nama</td><td>kampus</td><td>nim</td><td>edit</ td><td>delete</td></tr> <?php include "config.php"; $pilihan=mysql_query("select * from tutorialsatu"); $no=1; while($w=mysql_fetch_array($pilihan)){ echo"<tr><td>$no</td> <td>$w[nama]</td> <td>$w[kampus]</td> <td>$w[nim]</td> <td><a href=modif.php?id=$w[id]>edit</a></td><td><a href=delete.php?id=$w[id]>delete</a></td> </tr>"; $no++; } ?> </table> </body> </html>
www.muhamadali.besaba.com Page 7

5. Nah setelah itu sobat silakan buat satu file lagi dengan nama modif.php <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=iso-88591" /> <title>Untitled Document</title> <link rel="stylesheet" type="text/css" href="style.css" /> </head>

<body> <?php include "config.php"; $id = $_GET['id']; $editan = mysql_query("SELECT * FROM tutorialsatu WHERE id='$id'"); $susunan = mysql_fetch_array($editan); ?>

<form method="post" action="modifproses.php"> <input type=hidden name=id value="<?php echo $id;?>"> <table>
www.muhamadali.besaba.com Page 8

<tr> <td>EDIT</td> </tr> <tr> <td>nama</td> <td><input name="nama" type="text" value="<?php echo $susunan['nama'];?>" /></td> </tr> <tr> <td>kampus</td><td> <input name="kampus" type="text" value="<?php echo $susunan['kampus'];?>" /></td> </tr> <tr><td>Nim</td><td><input type=text name=nim value="<?php echo $susunan['nim'];?>"></td> </tr></table> <input type=submit name=submit > </body> </html>

6. Ini file untuk modifproses.php nya


======================== <?php include "config.php"; mysql_query("update tutorialsatu set nama='$_POST[nama]', kampus='$_POST[kampus]', nim='$_POST[nim]' where id='$_POST[id]'"); header('location:index.php'); ?>
www.muhamadali.besaba.com Page 9

7. Sementara yang terakhir ini adalah file untuk memproses


delete.php silakan simpan dengan nama delete.php <?php include "config.php"; mysql_query("delete from tutorialsatu where id='$_GET[id]'"); header("location:index.php"); ?>

=====================================================

Oke demikian duluyah,dari ane,apabila ada kekurangan mohon maaf,kita sama-sama belajar,,,,,wek.wek..supaya lebh kenal lagi berikut biodata penulis,,,

Perkenalkan nama ane Muhamad Ali,panggil saja Ali atau Al,nah sekarang ini ane masih kuliah di salah satu sekolah Tinggi suwasta,pada semester 4.ane uga dulu pernah sekolah di SMA N 1 Losarang,,lulus kemudian melanjutkan kuliah di jurusan Tehnik Komputer dan Informatika di BSI dan STMIK Nusa Mandiri. Yah demikian singkatdeh perkenalan dari ane, teriakasih telah mengunjungi website ane di www.muhamadali.besaba.com ,apa bila banyak kekurangan ane mohon maff,,,

www.muhamadali.besaba.com

Page 10

semoga kita menjadi orang yang bermanfaat untuk orang lain,,amin,,,

www.muhamadali.besaba.com

Page 11

Anda mungkin juga menyukai