1. index1.php
2. frm_edit_data.php
3. frm_tambah_data.php
4. save_data.php
5. delete_data.php
1. index1.php
<?php
include('../inc-db.php');
error_reporting(0);
$sqlShow="SELECT * FROM tb_mahasiswa ";
$result=mysql_query($sqlShow);
?>
<table border='1'><a href="frm_tambah_data.php">Tambah Data</a>
<tr><td><b>No</b></td><td><b>Nim</b></td><td><b>Nama</b></td><td><b>Alamat</b></td><td><b>Action</b></td></tr>
<?php
$no=$posisi+0;
while($data=mysql_fetch_array($result)){
$no++;
?>
<tr>
<td><?php echo $no; ?></td>
<td><?php echo $data['nim']; ?></td>
<td><?php echo $data['nama']; ?></td>
<td><?php echo $data['alamat']; ?></td>
<td>
<a href="frm_edit_data.php?id=<?php echo $data['id']; ?>">edit</a> | <a href="delete_data.php?delete=<?php echo $data['id']; ?>">delete</a></td>
</tr>
<?php
}
?>
</table>
2. frm_edit_data.php
<?php
include('../inc-db.php');
$ambil_parameter_id=$_GET['id'];
$sqlShow="SELECT * FROM tb_mahasiswa WHERE id='".$ambil_parameter_id."'";
$result=mysql_query($sqlShow);
$data=mysql_fetch_array($result);
?>
<form id="form1" name="form1" method="post" action="update_data.php">
<table width="200" border="0">
<tr>
<td>Nim</td>
<td>:</td>
<td>
<input type="text" name="frm_nim" id="frm_nim" value="<?php echo $data['nim']; ?>" />
<input type="hidden" name="ambil_id" id="ambil_id" value="<?php echo $data['id']; ?>"/>
</td>
</tr>
<tr>
<td>Nama</td>
<td>:</td>
<td><input type="text" name="frm_nama" id="frm_nama" value="<?php echo $data['nama']; ?>"/>
</td>
</tr>
<tr>
<td><p>Alamat</p>
<p> </p></td>
<td> </td>
<td><textarea name="frm_alamat" id="frm_alamat"><?php echo $data['alamat']; ?></textarea></td>
</tr>
<tr>
<td> </td>
<td> </td>
<td>
<input type="submit" name="Submit" value="UPDATE" id="Submit" />
</td>
</tr>
</table>
</form>
3. frm_tambah_data.php
<form id="form1" name="form1" method="post" action="save_data.php">
<table width="200" border="0">
<tr>
<td>Nim</td>
<td>:</td>
<td>
<input type="text" name="frm_nim" id="frm_nim" />
</td>
</tr>
<tr>
<td>Nama</td>
<td>:</td>
<td><input type="text" name="frm_nama" id="label" />
</td>
</tr>
<tr>
<td><p>Alamat</p>
<p> </p></td>
<td> </td>
<td><textarea name="frm_alamat" id="frm_alamat"></textarea></td>
</tr>
<tr>
<td> </td>
<td> </td>
<td>
<input type="submit" name="Submit" value="SAVE" id="Submit" />
</td>
</tr>
</table>
</form>
4. save_data.php
<?php
include('../inc-db.php'); //ambil koneksi ke database mysql
$var_nim=$_POST['frm_nim'];
$var_nama=$_POST['frm_nama'];
$var_alamat=$_POST['frm_alamat'];
$sqlInsert="INSERT INTO tb_mahasiswa VALUES ('','".$var_nim."','".$var_nama."','".$var_alamat."')";
//echo $sqlInsert;
//exit;
$result=mysql_query($sqlInsert);
header('location: index1.php');
?>
5. delete_data.php
<?php
include('../inc-db.php');
$var_ambil_id=$_GET['delete'];
$sqlDelete="delete from tb_mahasiswa where id=".$var_ambil_id."";
//echo $sqlDelete;
//exit;
$result=mysql_query($sqlDelete);
header('location: index1.php');
?>
2. frm_edit_data.php
3. frm_tambah_data.php
4. save_data.php
5. delete_data.php
CREATE DATABASE `db_ruangprogramer`;
USE db_ruangprogramer;
CREATE TABLE `tb_mahasiswa` (
`id` INT(11) UNSIGNED NOT NULL AUTO_INCREMENT,
`nim` VARCHAR(12) DEFAULT NULL,
`nama` VARCHAR(12) DEFAULT NULL,
`alamat` VARCHAR(12) DEFAULT NULL,
PRIMARY KEY (`id`)
) ENGINE=INNODB AUTO_INCREMENT=28 DEFAULT CHARSET=latin1
1. index1.php
<?php
include('../inc-db.php');
error_reporting(0);
$sqlShow="SELECT * FROM tb_mahasiswa ";
$result=mysql_query($sqlShow);
?>
<table border='1'><a href="frm_tambah_data.php">Tambah Data</a>
<tr><td><b>No</b></td><td><b>Nim</b></td><td><b>Nama</b></td><td><b>Alamat</b></td><td><b>Action</b></td></tr>
<?php
$no=$posisi+0;
while($data=mysql_fetch_array($result)){
$no++;
?>
<tr>
<td><?php echo $no; ?></td>
<td><?php echo $data['nim']; ?></td>
<td><?php echo $data['nama']; ?></td>
<td><?php echo $data['alamat']; ?></td>
<td>
<a href="frm_edit_data.php?id=<?php echo $data['id']; ?>">edit</a> | <a href="delete_data.php?delete=<?php echo $data['id']; ?>">delete</a></td>
</tr>
<?php
}
?>
</table>
2. frm_edit_data.php
<?php
include('../inc-db.php');
$ambil_parameter_id=$_GET['id'];
$sqlShow="SELECT * FROM tb_mahasiswa WHERE id='".$ambil_parameter_id."'";
$result=mysql_query($sqlShow);
$data=mysql_fetch_array($result);
?>
<form id="form1" name="form1" method="post" action="update_data.php">
<table width="200" border="0">
<tr>
<td>Nim</td>
<td>:</td>
<td>
<input type="text" name="frm_nim" id="frm_nim" value="<?php echo $data['nim']; ?>" />
<input type="hidden" name="ambil_id" id="ambil_id" value="<?php echo $data['id']; ?>"/>
</td>
</tr>
<tr>
<td>Nama</td>
<td>:</td>
<td><input type="text" name="frm_nama" id="frm_nama" value="<?php echo $data['nama']; ?>"/>
</td>
</tr>
<tr>
<td><p>Alamat</p>
<p> </p></td>
<td> </td>
<td><textarea name="frm_alamat" id="frm_alamat"><?php echo $data['alamat']; ?></textarea></td>
</tr>
<tr>
<td> </td>
<td> </td>
<td>
<input type="submit" name="Submit" value="UPDATE" id="Submit" />
</td>
</tr>
</table>
</form>
3. frm_tambah_data.php
<form id="form1" name="form1" method="post" action="save_data.php">
<table width="200" border="0">
<tr>
<td>Nim</td>
<td>:</td>
<td>
<input type="text" name="frm_nim" id="frm_nim" />
</td>
</tr>
<tr>
<td>Nama</td>
<td>:</td>
<td><input type="text" name="frm_nama" id="label" />
</td>
</tr>
<tr>
<td><p>Alamat</p>
<p> </p></td>
<td> </td>
<td><textarea name="frm_alamat" id="frm_alamat"></textarea></td>
</tr>
<tr>
<td> </td>
<td> </td>
<td>
<input type="submit" name="Submit" value="SAVE" id="Submit" />
</td>
</tr>
</table>
</form>
4. save_data.php
<?php
include('../inc-db.php'); //ambil koneksi ke database mysql
$var_nim=$_POST['frm_nim'];
$var_nama=$_POST['frm_nama'];
$var_alamat=$_POST['frm_alamat'];
$sqlInsert="INSERT INTO tb_mahasiswa VALUES ('','".$var_nim."','".$var_nama."','".$var_alamat."')";
//echo $sqlInsert;
//exit;
$result=mysql_query($sqlInsert);
header('location: index1.php');
?>
5. delete_data.php
<?php
include('../inc-db.php');
$var_ambil_id=$_GET['delete'];
$sqlDelete="delete from tb_mahasiswa where id=".$var_ambil_id."";
//echo $sqlDelete;
//exit;
$result=mysql_query($sqlDelete);
header('location: index1.php');
?>
Tidak ada komentar:
Posting Komentar