-- phpMyAdmin SQL Dump -- version 3.4.5 -- http://www.phpmyadmin.net -- -- Host: localhost -- Generation Time: Jan 21, 2014 at 02:32 PM -- Server version: 5.5.16 -- PHP Version: 5.3.8 SET SQL_MODE="NO_AUTO_VALUE_ON_ZERO"; SET time_zone = "+00:00"; /*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */; /*!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS */; /*!40101 SET @OLD_COLLATION_CONNECTION=@@COLLATION_CONNECTION */; /*!40101 SET NAMES utf8 */; -- -- Database: `test` -- -- -------------------------------------------------------- -- -- Table structure for table `mhsasia` -- CREATE TABLE IF NOT EXISTS `mhsasia` ( `id` int(10) NOT NULL AUTO_INCREMENT, `nama` text NOT NULL, `alamat` char(30) NOT NULL, `nim` char(8) NOT NULL, `email` char(28) NOT NULL, `no_telpon` char(18) NOT NULL, PRIMARY KEY (`id`) ) ENGINE=InnoDB DEFAULT CHARSET=latin1 ROW_FORMAT=COMPACT AUTO_INCREMENT=17 ; -- -- Dumping data for table `mhsasia` -- INSERT INTO `mhsasia` (`id`, `nama`, `alamat`, `nim`, `email`, `no_telpon`) VALUES (1, 'Samari Sulfin', 'Jln. Panguripan 36A Gg. IIIB', '08201167', 'sam_caem@yahoo.co.id', '089121474836'), (2, 'Daniel Noor', 'Jln. Kedangagung 12', '07201127', 'daniel_nur88@gmail.com', '08916600663'), (3, 'Cah Pucanglaban', 'Jln. Asia Selatan No. 10C', '08201144', 'huda_caem12@yahoo.com', '08992213660'), (4, 'Moor Gand UL', 'Jln. Panarukan 11B Wedangan', '08201078', 'gandaasiaselatan@yahoo.com', '0899333767'), (5, 'Hehen Pengend di Manja', '', '127', '', '0'), (6, 'Noor Manny', '', '127', '', '0'), (7, 'Dloow Jail', '', '127', '', '0'), (8, 'Paijo Romeo', '', '127', '', '0'), (9, 'Moammar Khaniv', '', '127', '', '0'); /*!40101 SET CHARACTER_SET_CLIENT=@OLD_CHARACTER_SET_CLIENT */; /*!40101 SET CHARACTER_SET_RESULTS=@OLD_CHARACTER_SET_RESULTS */; /*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */;
Copy aja Query diatas ke Notepad dan jadikan mhsasia.sql
<?php $host="localhost"; $user="root"; $pass=""; $db="test"; $koneksi=mysql_connect($host,$user,$pass); mysql_select_db($db,$koneksi); ?>
<center><h1>Tambah Data</h1></center>
<form method="post" action="simpan.php">
<table align="center" frame="box" bgcolor="#CCCCCC">
<tr><td>ID</td>
<td><input type="text" name="id" size="8" /></td>
</tr>
<tr><td>Nama</td>
<td><input type="text" name="nama" size="20" /></td>
</tr>
<tr><td>Alamat </td>
<td><input type="text" name="alamat" size="30" /></td>
</tr>
<tr>
<td>NIM</td>
<td><input type="text" name="nim" size="10" /></td>
</tr>
<tr>
<td>Email</td>
<td><input type="text" name="email" size="28" /></td>
</tr>
<tr><td>No Telp</td>
<td><input type="text" name="no_telpon" size="18" /></td>
</tr>
<tr>
<td><input type="submit" name="simpan" value="Simpan"></td>
<td><input type="reset" name="reset" value="Reset"></td>
</tr>
</table>
</form>
<?php
echo ("<center>Lihat Data <a href=\"view.php\">OK</a></center>");
?>
<?php
include("koneksi.php");
$id = $_POST['id'];
$nama = $_POST['nama'];
$alamat = $_POST['alamat'];
$nim = $_POST['nim'];
$email = $_POST['email'];
$no_telpon = $_POST['no_telpon'];
$query = mysql_query("insert into mhsasia values ('$id','$nama','$alamat','$nim','$email','$no_telpon')");
echo ("<center>Data Telah di Simpan<br><a href=\"index.php\">Kembali</a></center><br>");
echo ("<center>Lihat Data !!! <a href=\"view.php\">OK</a></center>");
?>
<?php
include "koneksi.php";
$perintah="select*from mhsasia order by id asc";
$hasil=mysql_query($perintah);
echo("<table border='1' align='center'>");
echo("<tr><center><h3>Data Mahasiswa</h3></center></tr>
<tr><th>No.</th><th>ID</th><th>Nama</th><th>Alamat</th><th>NIM</th><th>Email</th><th>No Telpon</th></tr>");
$no=1;
while($row=mysql_fetch_array($hasil))
{
echo("<tr>");
echo("<td>$no</td>");
list($id,$nama,$alamat,$nim,$email,$no_telpon)=$row;
echo("<td>$id</td><td>$nama</td><td>$alamat</td><td>$nim</td><td>$email</td><td>$no_telpon</td>");
echo("<td><font size='1'><a href=\"edit.php?id=$id\">Edit</a></font></td>");
echo("<td><font size='1'><a href=\"hapus.php?id=$id\">Hapus</a></font></td></tr>");
echo("</tr>");
$no++;
$end;
}
echo("</table>");
echo ("<br><center>Tambah Data <a href=\"index.php\">OK</a></center>");
?>
<?php
include "koneksi.php";
$id = $_GET['id'];
$perintah = "select * from mhsasia where id='$id'";
$hasil = mysql_query($perintah, $koneksi) or die("gagal melakukan query");
$row = mysql_fetch_array($hasil);
mysql_close($koneksi);
?>
<form method="post" action="update.php">
<table align="center" bordercolor="#999999" bgcolor="#CCCCCC">
<tr><td>ID</td><td><input type="text" name="id" value="<?php echo $row['id']; ?>"></td></tr>
<tr><td>Nama</td><td><input type="text" name="nama" value="<?php echo $row['nama']; ?>"></td></tr>
<tr><td>Alamat</td><td><input type="text" name="alamat" value="<?php echo $row['alamat']; ?>" size="30"></td></tr>
<tr><td>NIM</td><td><input type="text" name="nim" value="<?php echo $row['nim']; ?>"></td></tr>
<tr><td>Email</td><td><input type="text" name="email" value="<?php echo $row['email']; ?>"></td></tr>
<tr><td>No. telpon</td><td><input type="text" name="no_telpon" value="<?php echo $row['no_telpon']; ?>"></td></tr>
<tr><td><input value="Simpan" type="submit" name="submit"/></td>
<td><input type="button" value="Kembali" onClick="self.history.back()"></td></tr>
</table>
</form>
<?php
include("koneksi.php");
$id = $_POST['id'];
$nama = $_POST['nama'];
$alamat = $_POST['alamat'];
$nim = $_POST['nim'];
$email = $_POST['email'];
$no_telpon = $_POST['no_telpon'];
$query = mysql_query("update mhsasia set nama='$nama', alamat='$alamat', nim='$nim', email='$email',no_telpon='$no_telpon' where id='$id'");
echo "<center><h2><strong>Data Telah di Update</strong></h2><br><hr><a href=\"view.php\">OK</a></center>";
?>
<?php
include("koneksi.php");
mysql_query("DELETE from mhsasia WHERE id='$_GET[id]'");
echo"<center><h2><strong>Data Telah di Hapus</strong></h2><br><hr><a href=\"view.php\">OK</a></center>";
?>
Simpan dalam satu folder, panggil seperti biasa, tampilan sederhana dan simple.
Selesai.
:>)
ReplyDeletenice tutorial...
ReplyDeleteTerimakasih gan ilmunya...sangat bermanfaat
ReplyDeleteKunjungi kembali blog ane yang postnya berkaitan dengan insert data.membuat nomor ID otomatis
http://arsipbertuah.blogspot.co.id/2015/11/simpan-data-dan-id-otomatis-php-mysql.html
This comment has been removed by the author.
ReplyDeleteMaaf saya mau tanya, saya masih bingung kok database gak muncul yah?
ReplyDeletepadahal saya sudah konek ke Xampp dan sudah buat database nya di PhpmyAdmin nah, itu salahnya dimana yah?
terimakasih