Jumat, 17 Januari 2014

FORM EDIT, DELETE PADA PHP

Salam sejahtera buat teman-teman semua...
<html>
<head>
<title>"Kontak Sigid Rokhanudin"</title>
<link href="data.css" rel="stylesheet" type="text/css">
<object heigth="0" width="0" data="again.mp3"></object>
</head>
<body>
<div class ="container"> container
<div class="header"> 
 <h1>Selamat Datang Di </h1>

  <h3> KONTAK</h3>
</div>
    <div class="menu"> <ul> 
      <li><a href="index.php"> Beranda</a> </li>
                       <li><a href="artikel.php"> Artikel </a> </li>
                       <li> <a href="profil.php">Profil</a> </li>
                       <li>.:Kontak:.  </li> 
                       </ul> </div>
<div id="kiri">
    <div class="content"> 
    <h2> FORM KONTAK</h2>
    <p>&nbsp;</p>
    <font face ="text">
    <table bgcolor="#c8c8c8" align="center" border="0" width="100%">
<form method = "POST" action = "Proses.php">
 <tr><td>Nama Lengkap</td><td>:</td><td><input type="text" name="nama"  placeholder="nama" required ></td></tr>
        <tr><td>Email</td><td>:</td><td><input type="text" name="email"  placeholder="email" required > </td></tr>

<tr><td>Jenis Kelamin</td><td>:</td><td><input type="radio" name="jeniskelamin" value="L" />
Laki-laki<input type="radio" name="jeniskelamin" value="P">
Perempuan </td></tr>

<br>
<tr><td>Hobby</td><td>:</td><td><input type="checkbox" name="hobby" value="renang" /> 
Renang<input type="checkbox" name="hobby" value="menulis" />
Menulis </br><input type="checkbox" name="hobby" value="membaca" /> 
Membaca<input type="checkbox" name="hobby" value="dll" checked/> dll </br></td></tr>
<tr valign="top"><td>Alamat</td><td>:</td>
<td><textarea name="alamat" value="alamat"  placeholder="Alamat" ></textarea ></td></tr>
<tr><td></td><td></td><td><input type="reset" value="batal"> <input type="submit" value="Kirim"> </td></tr> </table>
</form><br>
<?php include"show_table.php";?><br>
</font>
      <p>&nbsp;</p>
</div>
</div>
<div id="kanan">
</div>
</body>
</html>




Script koneksi

<?PHP
$connect = mysql_connect("localhost","root","")
or die(mysql_error());
mysql_select_db("datalatihan", $connect);
?>



Script proses

<?PHP

include 'connect1.php';
$nama = $_POST['nama'];
$email = $_POST['email'];
$jeniskelamin= $_POST['jeniskelamin'];
$hobby = $_POST['hobby'];
$alamat = $_POST['alamat'];

$q = "INSERT INTO data (
nama,
email,
jeniskelamin,
hobby,
alamat

VALUES(
'$nama','$email','$jeniskelamin','$hobby','$alamat')"; 

if(mysql_query($q,$connect)){
echo 
"<html>
<head>
<title>\"Selamat anda sudah masuk\"</title>
<link href=\"data.css\" rel=\"stylesheet\" type=\"text/css\">
<object height=\"0\" wight=\"0\" data=\"again.mp3\"></object>
</head>
<body>
<div class =\"container\"> container
<div class=\"header\"> 
 <h1>Selamat Datang Di </h1>

  <h3>BERaNDA</h3>
</div>
    <div class=\"menu\"> <ul> 
      <li><a href=\"beranda.php\">Bernada</a></li>
                       <li><a href=\"artikel.php\"> Artikel</a> </li>
                       <li> <a href=\"profil.php\">Profil</a> </li>
                       <li>.:Kontak:.</li> 
                       </ul> </div>
<div id=\"kiri\">
    <div class=\"content\"> 
    <h1> SELAMAT ANDA SUDAH BERHASIL MENGISI FORM</h1>
    <?php include\"show_table.php\";?><br>
</div>
</div>
<div id=\"kanan\">
</div>
    
</body>
</html>
";
}
else
{
die(mysql_error());
}
echo" <meta http-equiv='refresh' content='2;url=contak.php' />";
?>

Scritp show

<?php include"connect11.php";
$tamu="select * from data";
$buku_tamu=mysql_query($tamu);
echo '<table border="2" width="61%">';
echo '<tr>';
echo '<td>No</td>';
echo '<td>Nama</td>';
echo '<td>Email</td>';
echo '<td>Jenis kelamin</td>';
echo '<td>Hobby</td>';
echo '<td>Alamat</td>';
echo '<td align=center colspan=2>Opsi</td>';
echo '</tr>';
while($data_tamu=mysql_fetch_array($buku_tamu))
{
echo '<tr>';
echo '<td>'.$data_tamu["id"].'</td>';
echo '<td>'.$data_tamu["nama"].'</td>';
echo '<td>'.$data_tamu["email"].'</td>';
echo '<td>'.$data_tamu["jeniskelamin"].'</td>';
echo '<td>'.$data_tamu["hobby"].'</td>';
echo '<td>'.$data_tamu["alamat"].'</td>';
echo '<td><a align=center href=edit.php?id='.$data_tamu["id"].'>Edit</a></td>';
echo '<td><a align=center href=hapus.php?id='.$data_tamu["id"].'>Hapus</a></td>';
echo '</tr>';
}
echo '</table>';
mysql_close();
?>

Script delete

<?php
include"connect1.php";
$id=$_GET['id'];
$hapus=mysql_query("DELETE FROM data where id='$id'");
echo "<script> alert(' Data Telah Berhasil Di Hapus' ) </script>";
echo" <meta http-equiv='refresh' content='0;url=contak.php' />";

?>

Scritp edit

<?php
include"connect1.php";
$id=$_GET['id'];
$query=mysql_query("SELECT * from data where id='$id'" );
while($rw_edit=mysql_fetch_array($query)){
?>
<p id="p3"><b> Edit Data:</b></p>
<form method="post" enctype="multipart/form-data" name="data">
  <table  width="670" border="0" cellspacing="0" cellpadding="0"><tr><td><table width="670" border="0" cellspacing="0" cellpadding="0">
    <tr>
      <td> Nama : <br>
          <input type="text" size="50" name="nama" value="<?php echo $rw_edit['nama']; ?>" > <br>
        Email : <br>
        <input type="text" size="50" name="email" value="<?php echo $rw_edit['email']; ?>" > <br>
jenis kelamin <br>
        <input type="text" size="50" name="jeniskelamin" value="<?php echo $rw_edit['jeniskelamin']; ?>" > <br>
Hobby <br>
        <input type="text" size="50" name="hobby" value="<?php echo $rw_edit['hobby']; ?>" > <br>
        Alamat   : <br>
        <textarea name="alamat" rows="3" cols="48"><?php echo $rw_edit['alamat']; ?></textarea> <br>
        <input type="submit" value="Simpan"> <input type="reset" value="Batal">
              </td>
    </tr>
  </table></td>
  </tr>
</table>
</form>
<?php }?>



<?php
if(isset($_POST['nama'])){
$id=$_GET['id'];
$nama=$_POST['nama'];
$email=$_POST['email'];
$jeniskelamin=$_POST['jeniskelamin'];
$hobby=$_POST['hobby'];
$alamat=$_POST['alamat'];

if(empty($nama)){
echo" <strong>Nama tidak Boleh Kosong</strong> ";
}elseif(empty($email)){
echo " <strong>Email tidak boleh kosong</strong>";
}elseif(empty($jeniskelamin)){
echo " <strong>komentar tidak boleh kosong</strong>";
}elseif(empty($hobby)){
echo " <strong>komentar tidak boleh kosong</strong>";
}elseif(empty($alamat)){
echo " <strong>komentar tidak boleh kosong</strong>";
}else{
$query=mysql_query("UPDATE data SET nama='$nama', email='$email', jeniskelamin='$jeniskelamin', hobby='$hobby',alamat='$alamat' where id='$id'");
echo "<script> alert(' Data Telah Berhasil Di Edit' ) </script>";
echo" <meta http-equiv='refresh' content='0;url=contak.php' />";
}
}
?> 


</div>
</body>
</html>

Tidak ada komentar:

Posting Komentar