Monday, October 17, 2011

Tutorial PHP simpan hapus cari data

Nama database : mhs

Nama tabel : datamhs

Field : nim int(5),nama var(20)

User: root, password=kosong

Tampilan formulir. html


="isi.php" method="post">

nomor:

nama:

// isi.php

$nim=$_POST['nim'];

$nama=$_POST['nama'];

$sambung=mysql_connect("localhost","root","");

$pildb=mysql_select_db("mhs",$sambung);

$perintah="insert into datamhs (nim, nama)

Values ('$nim','$nama')";

mysql_query($perintah,$sambung);

echo "1 record ditambah";

echo "[ Isi lagi ]";

echo "[ Edit ]";

mysql_close($sambung);

?>


Tampilan Edit.html


// edit.php

$sambung=mysql_connect("localhost","root","");

$pildb=mysql_select_db("mhs",$sambung);

$perintah="select * from datamhs";

$hasil=mysql_query($perintah,$sambung);

echo "

";

echo "

";

echo "

";

echo "

";

echo "

";

echo"

";

echo "

";

while($cetak=mysql_fetch_array($hasil)) {

echo "

";

echo "

";

echo "

";

echo "

";

}

echo "

Nomor Nama Lengkap pilihan
".$cetak['nim']." ".$cetak['nama']." ";

echo "";

echo "hapus

";

mysql_close($sambung);

?>

//delete.php

$sambung=mysql_connect("localhost","root","");

$pildb=mysql_select_db("mhs",$sambung);

$nomorku=$_GET['no'];

$perintah="delete from datamhs where nim=$nomorku";

mysql_query($perintah,$sambung);

echo "data berhasil dihapus";

echo "
";

echo "[ Isi lagi ]";

echo "[ Edit ]";

?>


Tampilan cari.html


// cari.php

$sambung=mysql_connect("localhost","root","");

$pildb=mysql_select_db("mhs",$sambung);

$nomorku=$_POST['carikata'];

$perintah="select * from datamhs where nama like '%$nomorku%'";

$hasil=mysql_query($perintah,$sambung);

$jumlah=mysql_num_rows($hasil);

if ($jumlah>0) {

echo "ditemukan data sebanyak :".$jumlah;

echo "
";

echo "Yang memiliki nama : ".$nomorku;

echo " adalah nim";

echo "
";

while($cetak=mysql_fetch_array($hasil)) {

echo $cetak['nim'];

echo "
";

}

}

else {

echo "maaf tidak ditemukan";

}

?>

No comments:

Post a Comment

Tuliskan komentar anda