- Pembuatan form update untuk mengubah data yang sudah diinput
1: <?php
2: include("phpclass/CMahasiswa.php");
3: $nimna = $_GET['nim'];
4: $cm = new CMahasiswa();
5: $query = $cm->getEdit($nimna);
6: $hasil = mysql_fetch_array($query);
7: ?>
8: <form action="updateMahasiswa.php" method="POST" class="form-horizontal" role="form">
9: <input type="hidden" name="nim_asli" value="<?=$hasil[0];?>">
10: <div class="form-group">
11: <label class="col-md-4 control-label">NIM</label>
12: <div class="col-md-6">
13: <input type="text" class="form-control" name="nim" value="<?=$hasil[0];?>" placeholder="ex:1808208" maxlength="8" />
14: </div>
15: </div>
16: <div class="form-group">
17: <label class="col-md-4 control-label">Nama Mahasiswa</label>
18: <div class="col-md-6">
19: <input type="text" class="form-control" name="nmmhs" value="<?=$hasil[1];?>" placeholder="ex:sumpeno" />
20: </div>
21: </div>
22: <div class="form-group">
23: <label class="col-md-4 control-label">Jenis Kelamin</label>
24: <div class="col-md-6">
25: <input type="radio" name="jnskel" value="Laki-Laki" <?php echo $hasil[2]=='Laki-Laki'?'checked="checked"':'';?> />Laki-Laki
26: <input type="radio" name="jnskel" value="Perempuan" <?php echo $hasil[2]=='Perempuan'?'checked="checked"':'';?> />Perempuan
27: </div>
28: </div>
29: <div class="form-group">
30: <label class="col-md-4 control-label">Agama</label>
31: <div class="col-md-6">
32: <select size="1" name="agama" class="form-control">
33: <option value="Islam" <?php echo $hasil[3]=='Islam'?'selected="selected"':'';?> >Islam</option>
34: <option value="Kristen" <?php echo $hasil[3]=='Kristen'?'selected="selected"':'';?>>Kristen</option>
35: <option value="Katholik" <?php echo $hasil[3]=='Katholik'?'selected="selected"':'';?>>Katholik</option>
36: <option value="Budha" <?php echo $hasil[3]=='Budha'?'selected="selected"':'';?>>Budha</option>
37: <option value="Hindu" <?php echo $hasil[3]=='Hindu'?'selected="selected"':'';?>>Hindu</option>
38: </select>
39: </div>
40: </div>
41: <div class="form-group">
42: <div class="col-md-6 col-md-offset-4">
43: <button type="submit" class="btn btn-primary">Simpan</button>
44: <button type="reset" class="btn btn-danger" onclick="history.go(-1)">Batal</button>
45: </div>
46: </div>
47: </form>
Tampilannya akan menjadi sebagai berikut:
|
Form Update Mahasiswa |
formUpdateMatakuliah.php
1: <?php
2: include("phpclass/CMatkul.php");
3: $kodena= $_GET['kode'];
4: $cm = new CMatkul();
5: $query = $cm->getEdit($kodena);
6: $hasil = mysql_fetch_array($query);
7: ?>
8: <form name="frmMatkul" action="updateMatakuliah.php" method="POST" class="form-horizontal" role="form">
9: <input type="hidden" name="kode_asli" value="<?=$hasil[0];?>">
10: <div class="form-group">
11: <label class="col-md-4 control-label">Kode</label>
12: <div class="col-md-6">
13: <input type="text" class="form-control" name="kode" value="<?=$hasil[0];?>" required="required" maxlength="3" />
14: </div>
15: </div>
16: <div class="form-group">
17: <label class="col-md-4 control-label">Mata Kuliah</label>
18: <div class="col-md-6">
19: <input type="text" class="form-control" name="matakuliah" value="<?=$hasil[2];?>" required="required" />
20: </div>
21: </div>
22: <div class="form-group">
23: <label class="col-md-4 control-label">Kode Dosen</label>
24: <div class="col-md-6">
25: <input type="text" class="form-control" name="dosen" value="<?=$hasil[1];?>" required="required" maxlength="3" />
26: </div>
27: </div>
28: <div class="form-group">
29: <label class="col-md-4 control-label">Jumlah SKS</label>
30: <div class="col-md-6">
31: <input type="text" class="form-control" name="sks" value="<?=$hasil[3];?>" required="required" />
32: </div>
33: </div>
34: <div class="form-group">
35: <div class="col-md-6 col-md-offset-4">
36: <button type="submit" class="btn btn-primary">Simpan</button>
37: <button type="reset" class="btn btn-danger" onclick="history.go(-1)">Batal</button>
38: </div>
39: </div>
40: </form>
Tampilannya akan menjadi sebagai berikut:
|
Form Update Matakuliah |
Pembuatan file untuk menerima proses update dari form update
1: <?php
2: include ('phpclass/CMahasiswa.php');
3: $id = $_POST['nim_asli'];
4: $nim = $_POST['nim'];
5: $nmmhs = $_POST['nmmhs'];
6: $jnskel= $_POST['jnskel'];
7: $agama = $_POST['agama'];
8: $cm = new CMahasiswa();
9: $cm->setNim($nim);
10: $cm->setNamamahasiswa($nmmhs);
11: $cm->setJeniskelamin($jnskel);
12: $cm->setAgama($agama);
13: $hasil = $cm->getUpdate($id);
14: if($hasil){
15: ?>
16: <script language="javascript">
17: alert("Anda Berhasil Mengubah Data");
18: document.location="index.php?m=listMahasiswa";
19: </script>
20: <?php
21: }else{
22: ?>
23: <script language="javascript">
24: alert("Anda Gagal Mengubah Data");
25: history.go(-1);
26: </script>
27: <?php
28: }
29: ?>
updateMatakuliah.php
1: <?php
2: include('phpclass/CMatkul.php');
3: $id = $_POST['kode_asli'];
4: $kode = $_POST['kode'];
5: $matakuliah = $_POST['matakuliah'];
6: $sks = $_POST['sks'];
7: $dosen = $_POST['dosen'];
8: $mk = new CMatkul();
9: $mk->setKode($kode);
10: $mk->setMatakuliah($matakuliah);
11: $mk->setSks($sks);
12: $mk->setDosen($dosen);
13: $hasil = $mk->getUpdate($id);
14: if($hasil){
15: ?>
16: <script language="javascript">
17: alert("Anda berhasil mengubah data matakuliah");
18: document.location="index.php?m=listMatakuliah";
19: </script>
20: <?php
21: }else{
22: ?>
23: <script language="javascript">
24: alert("Anda Gagal mengubah data matakuliah");
25: history.go(-1);
26: </script>
27: <?php
28: }
29: ?>
Pembuatan Navigasi (navbar), halaman Home, dan proses Logout.
1: <nav class="navbar navbar-inverse">
2: <div class="container-fluid">
3: <div class="navbar-header">
4: <button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#bs-example-navbar-collapse-1">
5: <span class="sr-only">Toggle Navigation</span>
6: <span class="icon-bar"></span>
7: <span class="icon-bar"></span>
8: <span class="icon-bar"></span>
9: </button>
10: <a class="navbar-brand" href="#">Portal</a>
11: </div>
12: <div class="collapse navbar-collapse" id="bs-example-navbar-collapse-1">
13: <ul class="nav navbar-nav">
14: <li class="active">
15: <a href="index.php?m=home">Home</a>
16: </li>
17: <li>
18: <a href="index.php?m=listMahasiswa">Data Mahasiswa</a>
19: </li>
20: <li>
21: <a href="index.php?m=listMatakuliah">Data Matakuliah</a>
22: </li>
23: <li>
24: <a href="index.php?m=listAdmin">Data Admin</a>
25: </li>
26: </ul>
27: <?php
28: session_start(); #update: hapus saja
29: if($_SESSION['user'] != ''){
30: ?>
31: <ul class="nav navbar-nav navbar-right">
32: <li class="dropdown">
33: <a href="#" class="dropdown-toggle" data-toggle="dropdown"><?php echo ucwords($_SESSION['user']);?> <b class="caret"></b></a>
34: <ul class="dropdown-menu">
35: <li><a href="logout.php">Logout</a></li>
36: </ul>
37: </li>
38: </ul>
39: <?php
40: }else{
41: echo"";
42: }
43: ?>
44: </div>
45: </div>
46: </nav>
home.php
1: <h1> Halaman Home</h1>
2: <ol>
3: <li> <a href="index.php?m=formMahasiswa">Form Mahasiswa</a> </li>
4: <li> <a href="index.php?m=formMatakuliah">Form Matakuliah</a> </li>
5: </ol>
Tampilannya akan menjadi sebagai berikut:
|
Halaman Home |
logout.php
1: <?php
2: session_start();
3: session_destroy();
4: ?>
5: <script language="javascript">
6: alert("Logout Berhasil.");
7: document.location.href="index.php";
8: </script>
Okey, sampai disini pembahasan kita. Ini merupakan bagian akhir, seharusnya akan menghasilkan aplikasi yang lumayan baik. Silahkan melihat
demo atau download full code disini.
UPDATE:
Download full code nya:
download code
0 Response to " Membuat Halaman Adminisnistrator dan CRUD Menggunakan Konsep Pemrograman Berbasis Object (OOP) Bagian 6/6 "
Post a Comment