Thanks to visit codestin.com
Credit goes to www.scribd.com

0% found this document useful (0 votes)
254 views11 pages

Laporan Praktikum 10: PHP Dan Mysql 1

This document contains the source code for a student database website created using PHP and MySQL. It includes code for connecting to a MySQL database, pages for inputting, displaying, editing and deleting student records, and processing files to handle form submissions and database operations. The site allows users to manage a database of student information like name, student ID number, faculty and study program after logging in.

Uploaded by

Dian Monica
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
254 views11 pages

Laporan Praktikum 10: PHP Dan Mysql 1

This document contains the source code for a student database website created using PHP and MySQL. It includes code for connecting to a MySQL database, pages for inputting, displaying, editing and deleting student records, and processing files to handle form submissions and database operations. The site allows users to manage a database of student information like name, student ID number, faculty and study program after logging in.

Uploaded by

Dian Monica
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 11

LAPORAN PRAKTIKUM 10

PHP dan MySQL 1

Disusun untuk Memenuhi Matakuliah Pemrograman Berbasis Web


Dibimbing oleh Bapak Achmad Hamdan, S.Pd.,M.Pd.

Oleh :
Dian Monica
160533611453
S1 PTI’16 OFF A

UNIVERSITAS NEGERI MALANG


FAKULTAS TEKNIK
JURUSAN TEKNIK ELEKTRO
PRODI S1 PENDIDIKAN TEKNIK INFORMATIKA
November 2018
Folder dtmahasiswa

Database dtmahasiswa

Koneksi.php
<?php
mysql_connect("localhost","root","");
mysql_select_db("dtmahasiswa")or die (mysql_error());
?>
index.php
<?php
include"koneksi.php";
session_start();
if(isset($_SESSION['login'])){

?>
<html>
<head>
<style type="text/css">
.bg{
padding: 5px;
background-color:#008B8B;
border:0.5px;
}
.menu{
padding: 5px;
background-color:#008B8B;
color:white;
border:0.5px;
font-family:arial;
}
#link{
color:white;
text-align:right;
text-decoration:none;
font-weight: bold;
}
</style>
<title>Tuprak 1</title>
</head>
<body>
<form action="" method="post">
<div class="bg" >
<table>
<div id="menu">
<tr><td ><a href="?page=beranda" id="link"> | Beranda | </a></td>
<td ><a href="?page=input" id="link"> | Input Data | </a></td>
<td ><a href="?page=tampil" id="link"> | Tampil Data | </a></td>
<td><a href='login.php'id="link"> | Keluar | </a></td>
</tr></div></table></div>
</form>
</body>
</html>
<?php
}else{
die("Anda belum login! Anda tidak berhak
masuk ke dalam halaman ini. Silahkan Log In
<a href='tuprak_login.php'> disini</a>");}
?>
<?php
isset($_GET["page"])?$page=$_GET["page"]:$page="";
if($page=="beranda"){
include"beranda.php";
}elseif($page=="input"){
include"input.php";
}elseif($page=="tampil"){
include"tampil.php";
}elseif($page=="edit"){
include"proses_edit.php";
}else{
echo"Halaman Tidak Ditemukan";
}
?>
Input.php
<?php
include"koneksi.php";
?>
<style type="text/css">
#form{
margin-left:10px;
}
#form label{
width:60px;
float: left;
}
</style>
<div id="form">
<h3> Input Data</h3>
<form action="proses_input.php" method="post">
<label>Nama</label><input type="text" name="nama" /><br/>
<label>NIM</label><input type="text" name="nim"/><br/>
<label>Fakultas</label><input type="text" name="fakultas"/><br/>
<label>Prodi</label><input type="text" name="prodi"/><br/>
<input type="submit" value="Tambahkan"/>
<input type="Reset" value="Hapus"/>
</form>
</div>

Proses_input.php

<?php

include"koneksi.php";

$nim=$_POST["nim"];

$nama=$_POST["nama"];
$fakultas=$_POST["fakultas"];

$prodi=$_POST["prodi"];

mysql_query("insert into datamhs


values($nim,'$nama','$fakultas','$prodi')")

or die(mysql_error());

header("location:/dtmahasiswa/index_home.php?page=tampil");

?>
Tampil.php

<?php

include"koneksi.php";

?>

<?php

isset($_GET["page"])?$page=$_GET["page"]:$page="";

if($page=="edit"){

include"proses_edit.php";

}else{

echo"";

?>

<style type="text/css">

table{

margin-top:10px;

margin-left:10px;

</style>

<h3> Tampil Data</h3>

<table border="1">

<tr><th>Nama<th>NIM<th>Fakultas<th>Prodi<th>Edit<th>Hapus</th></tr>

<?php

$data=mysql_query("select*from datamhs");

while($data2=mysql_fetch_array($data)){

echo"<tr><td>$data2[nama]<td>$data2[nim]<td>

$data2[fakultas]<td>$data2[prodi]<td><a
href='index_home.php?page=edit&nim=$data2[nim]'>Edit</a><td><a
href='proses_hapus.php?nim=$data2[nim]'>Hapus</a></td></tr>";
}

?>

</table>

Proses_hapus.php

<?php

include"koneksi.php";

$nim=$_GET["nim"];

mysql_query("delete from datamhs where nim=$nim")

or die(mysql_error());

header("location:/dtmahasiswa/index_home.php?page=tampil");

?>
Proses_edit.php

<?php

include 'koneksi.php';

$nim = $_GET['nim']; //get the no which will updated

$query = "SELECT * FROM datamhs WHERE nim = $nim"; //get the data that
will be updated

$hasil = mysql_query($query);

$data = mysql_fetch_array($hasil);
?>

<style type="text/css">

#form{

margin-left:10px;

#form label{

width:60px;

float: left;

</style>

<div id="form">

<h3> Input Data</h3>

<form action="proses_edit2.php" method="post">

<label>Nama</label><input type="text" name="nama" value="<?php echo


$data['nama']; ?>"/><br/>

<label>NIM</label><input type="text" name="nim" value="<?php echo


$data['nim']; ?>"/><br/>

<label>Fakultas</label><input type="text" name="fakultas"


color="silver" value="<?php echo $data['fakultas']; ?>"/><br/>

<label>Prodi</label><input type="text" name="prodi" value="<?php echo


$data['prodi']; ?>"/><br/>

<input type="submit" value="Update"/>

</form>

</div>

Proses_edit2.php

<?php

include "koneksi.php";

//get the value from form update

$nim = $_POST['nim'];

$nama = $_POST['nama'];

$fakultas = $_POST['fakultas'];

$prodi = $_POST['prodi'];
//query for update data in database

$query = "UPDATE datamhs SET nama = '$nama', fakultas = '$fakultas',


prodi = '$prodi' WHERE nim = '$nim'" ;

$hasil = mysql_query($query);

//see the result

if ($hasil) {

header("location:/dtmahasiswa/index_home.php?page=tampil");

?>

You might also like