Selasa, 12 November 2013

PHP2

delete.php
<?php
    include 'koneksi.php';
    $nim = $_GET['nim'];
    $sql = mysql_query("delete from mahasiswa where nim=$nim");
    if($sql)
        echo 'Data terhapus';  
?>
update.php
<?php
    include 'koneksi.php';
    if(isset($_POST['simpan'])) {
        $nimlama = $_POST['nimlama'];
        $nim = $_POST['nim'];
        $nama = $_POST['nama'];
       
        $sql = mysql_query("UPDATE  `poltek`.`mahasiswa` SET  `nama` =  '$nama',`nim` = '$nim' WHERE  `mahasiswa`.`nim` =$nimlama");
        if($sql)
            echo 'Data terupdate';
    }
   
    $nim = $_GET['nim'];
    $sql = mysql_query("select * from mahasiswa where nim='$nim'");
    $r = mysql_fetch_array($sql);
    echo '<form method="post" action="">
            <input type="hidden" name="nimlama" value="'.$nim.'" />
            NIM<input type="text" name="nim" value="'.$r['nim'].'" /><br />
            Nama<input type="text" name="nama" value="'.$r['nama'].'"/><br />
            <input type="submit" name="simpan" value="Simpan" />
        </form>';
?>
index.php pakai delete dan edit
<?php
include 'koneksi.php';

$sql = mysql_query('select * from mahasiswa');
echo '<table border="1">';
echo '<tr>';
echo '<td>NIM</td>';
echo '<td>Nama</td>';
echo '<td>Action</td>';
echo '</tr>';
while($r = mysql_fetch_array($sql)) {
    echo '<tr>';
    echo '<td>'.$r['nim'].'</td>';
    echo '<td>'.$r['nama'].'</td>';
    echo '<td><a href="update.php?nim='.$r['nim'].'">Edit</a> <a href="delete.php?nim='.$r['nim'].'">Delete</a></td>';
    echo '</tr>';
}
echo '</table>';
echo '<a href="create.php">Tambah</a>';


0 komentar:

Posting Komentar

 
Thank you ....... | already - Visit My Blog |