Selasa, 04 Februari 2014

Tugas: PHP fungsi Insert, Select, Edit, Delete

http://difaums.besaba.com/lihat.php
DATABASE
Lihat Hasil disini

Komponen file:
koneksi.php

<?php
// file koneksi
$koneksi = mysql_connect("localhost","root","root");
$db = mysql_select_db("personalpage_difa");
?>
 
 
lihat.php
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Difa Website</title>
<link href="cssKu.css" type="text/css" rel="stylesheet" />
</head>

<body>
	<div id="header"> 
    	<span> " Difa Personal Site "</span>
    </div>
    <div id="menu_utama">
    	<a href="./"> Home </a>
        <a href="profile.php"> Profile </a>
        <a href="gallery.php"> Gallery </a>
        <span class="aktif"> Contact </span>
    </div>
    <div id="isi">
    	<h2>Hubungi saya :</h2>
        <form>
        <table width="600px" border="1" cellpadding="0" cellspacing="3px">
        <legend>Tabel data pesan | <a style="background-color:#FFF; padding:4px;" href="contact.php" title="Tambah pesan baru">[+] Pesan Baru</a></legend>
            <thead style="background-color:#CCCCCC">
                <th height="30px" align="center">Nama</th>
                <th align="center">Email</th>
                <th align="center">Website</th>
                <th align="center">Pesan</th>
                <th colspan="2" align="center">Menu</th>
            </thead>
			<?php
            // file aksi
            include("koneksi.php");
  			$qtampil = mysql_query("SELECT * FROM kontak");
			while($dat=mysql_fetch_array($qtampil)){
			?>            
            <tr align="center">
                <td><input type="text" value="<?php echo $dat[nama]; ?>" readonly></td>
                <td><input type="text" value="<?php echo $dat[email]; ?>" readonly></td>
                <td><input type="text" value="<?php echo $dat[website]; ?>" readonly></td>
                <td><input type="text" value="<?php echo $dat[pesan]; ?>" readonly></td>
                <td><a href="edit.php?idedit=<?php echo $dat[idkontak]; ?>" title="edit"> [e]</a></td>
                <td><a onClick="return confirm('Hapus data ini?')" href="hapus.php?idhapus=<?php echo $dat[idkontak]; ?>" title="hapus"> [x]</a></td>
            </tr>
            <?php } ?>
        </table>
        </form>
    </div>
    <div id="kaki">
    	&copy; 2013 Universitas Muhammadiyah Surakarta
    </div>
    
</body>
</html>
 


contact.php
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Difa Website</title>
<link href="cssKu.css" type="text/css" rel="stylesheet" />
</head>

<body>
	<div id="header"> 
    	<span> " Difa Personal Site "</span>
    </div>
    <div id="menu_utama">
    	<a href="./"> Home </a>
        <a href="profile.php"> Profile </a>
        <a href="gallery.php"> Gallery </a>
        <span class="aktif"> Contact </span>
    </div>
    <div id="isi">
    	<h2>Hubungi saya :</h2>
        <form method="post" enctype="multipart/form-data">
        <table width="600px" border="0" cellpadding="0" cellspacing="10px">
        <tr>
        <td width="100px"><strong>Nama</strong> * :</td>
        <td width="500px"><input type="text" size="50" name="nama" required ></td>
    	</tr>
        <tr>
        <td width="100px"><strong>Email</strong> * :</td>
        <td width="500px"><input type="email" size="50" name="email" required ></td>
    	</tr>
        <tr>
        <td width="100px"><strong>Website URL</strong> :</td>
        <td width="500px"><input type="text" size="50" name="website" required ></td>
    	</tr>
        <tr>
        <td width="100px"><strong>Pesan </strong>* :</td>
        <td width="500px"><textarea name="pesan" cols="38" rows="3" required></textarea></td>
    	</tr>
        <tr>
        <td width="100px"><p><strong>## NOTE ##</strong></p></td>
        <td width="500px"><input type="text" value="*) Field yang harus diisi" name="nb" readonly></td>
    	</tr>    
		<tr>
        <td colspan="2"><input type="submit" name="kirim" value="Kirim" > <a href="lihat.php"><input type="button" value="Lihat Data"></a></td>
    	</tr>
        </table>
        </form>
    </div>
    <div id="kaki">
    	&copy; 2013 Universitas Muhammadiyah Surakarta
    </div>
<?php
// file aksi
include("koneksi.php");

if($_POST[nama]){
	$nama = $_POST[nama];
	$email = $_POST[email];
	$web = $_POST[website];
	$pesan = $_POST[pesan];
	$tambah = mysql_query("INSERT INTO kontak(idKontak, nama, email, website, pesan) VALUES('','$nama','$email','$web','$pesan')");
?>
	<script>alert('Pesan dismpan ! Klik ok untuk melihat pesan.'); </script>
	<meta http-equiv="refresh" content="0; url=lihat.php" />
<?php } ?>
    
</body>
</html>




edit.php
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Difa Website</title>
<link href="cssKu.css" type="text/css" rel="stylesheet" />
</head>

<body>
	<div id="header"> 
    	<span> " Difa Personal Site "</span>
    </div>
    <div id="menu_utama">
    	<a href="./"> Home </a>
        <a href="profile.php"> Profile </a>
        <a href="gallery.php"> Gallery </a>
        <span class="aktif"> Contact </span>
    </div>
    <div id="isi">
    	<h2>Hubungi saya :</h2>
        <form method="post" enctype="multipart/form-data">
		<?php
        // file aksi
        include("koneksi.php");
		$idedit = $_GET[idedit];
        $qtampil = mysql_query("SELECT * FROM kontak WHERE idkontak='$idedit'");
        while($dat=mysql_fetch_array($qtampil)){
        ?>            
        
        <table width="600px" border="0" cellpadding="0" cellspacing="10px">
        <tr>
        <td width="100px"><strong>Nama</strong> * :</td>
        <td width="500px"><input type="text" size="50" name="nama" value="<?php echo $dat[nama]; ?>" required ></td>
    	</tr>
        <tr>
        <td width="100px"><strong>Email</strong> * :</td>
        <td width="500px"><input type="email" size="50" name="email" value="<?php echo $dat[email]; ?>" required ></td>
    	</tr>
        <tr>
        <td width="100px"><strong>Website URL</strong> :</td>
        <td width="500px"><input type="text" size="50" name="website" value="<?php echo $dat[website]; ?>" required ></td>
    	</tr>
        <tr>
        <td width="100px"><strong>Pesan </strong>* :</td>
        <td width="500px"><textarea name="pesan" cols="38" rows="3" required><?php echo $dat[pesan]; ?></textarea></td>
    	</tr>
        <tr>
        <td width="100px"><p><strong>## NOTE ##</strong></p></td>
        <td width="500px"><input type="text" value="*) Field yang harus diisi" name="nb" readonly></td>
    	</tr>    
		<tr>
        <td colspan="2"><input type="submit" name="kirim" value="Update" > <a href="lihat.php"><input type="button" value="Lihat Data"></a></td>
    	</tr>
        </table>
        <?php } ?>
        </form>
    </div>
    <div id="kaki">
    	&copy; 2013 Universitas Muhammadiyah Surakarta
    </div>
<?php
// file aksi

if($_POST[nama]){
	$nama = $_POST[nama];
	$email = $_POST[email];
	$web = $_POST[website];
	$pesan = $_POST[pesan];
	$edit = mysql_query("UPDATE kontak SET nama='$nama', email='$email', website='$web', pesan='$pesan' WHERE idkontak='$idedit'");
?>
	<script>alert('Pesan berhasil di edit ! Klik ok untuk daftar melihat pesan.'); </script>
	<meta http-equiv="refresh" content="0; url=lihat.php" />
<?php } ?>
    
</body>
</html>


hapus.php
<?php
// file aksi
include("koneksi.php");

$idhapus = $_GET[idhapus];
$hapus = mysql_query("DELETE FROM kontak WHERE idkontak='$idhapus'");
?>
	<script>alert('Pesan telah dihapus! Klik ok untuk kembali'); </script>
	<meta http-equiv="refresh" content="0; url=lihat.php" />

Tidak ada komentar:

Posting Komentar