Pertemuan-5 (PHP Koneksi MYSQL)
Download
Report
Transcript Pertemuan-5 (PHP Koneksi MYSQL)
Konektivitas PHP - MySQL
PHP - 2
Ir. H. Sumijan, M.Sc
Koneksi PHP - MySQL
Untuk melakukan koneksi PHP dengan MySQL digunakan
perintah: mysql_connect() -> skrip PHP.
Syntak:
mysql_connect(“hostname”,”username”,”password”);
Koneksi PHP - MySQL
Setelah terkoneksi, pilihlah database.
Bila database yang diinginkan belum
tersedia, buatlah databasenya.
Buatlah tabel, dengan struktur datanya.
Koneksi PHP - MySQL
<?
//Membuat database MySQL
$nama_db = “dbbola";
$buat_db = "create database $nama_db";
$sambung = mysql_connect("localhost","root","");
if($sambung){
echo "Koneksi Berhasil";}
else {
echo "Koneksi Gagal";}
$q_db = mysql_query($buat_db);
if($q_db){
echo "<br> Database $nama_db berhasil dibuat";}
else {
echo "<br> Database $nama_db gagal dibuat";}
?>
Koneksi Database
Koneksi PHP - MySQL
<?
//Membuat tabel MySQL
$nama_db = “dbbola";
$nama_tbl = "Liga";
$sambung = mysql_connect("localhost","root","");
if($sambung){
echo "Koneksi Berhasil";}
else {
echo "Koneksi Gagal";}
mysql_select_db($nama_db,$sambung) or
die("Koneksi ke $nama_db gagal");
$buat_tbl = "create table $nama_tbl (kode char(5)
not null, negara char(10) not null, champion int)";
$qtbl = mysql_query($buat_tbl,$sambung);
if($qtbl){
echo "<br>Tabel$nama_tbl berhasil dibuat";}
else {
echo "<br>Tabel $nama_tbl gagal dibuat";}
?>
Membuat Tabel
Koneksi PHP - MySQL
Membuat Form sebagai input pada sistem
database.
Input disimpan dalam satu tabel tertentu.
Pada attribut action ditentukan file yang
memiliki skrip PHP untuk menyimpan input
ke tabel pada database.
Koneksi PHP - MySQL
<html>
<head>
<title>Formulir Input Liga</title>
<meta author=Soe>
</head>
<body>
<h1>Masukkan Data Liga</h1>
<form method=post action=simpan.php>
<table>
<tr>
<td>Kode</td>
<td><input type=text name=kode size=20></td>
</tr>
<tr>
<td>Negara</td>
<td><input type=text name=negara size=20></td>
</tr>
Skrip – Form Input
Koneksi PHP - MySQL
<tr>
<td>Champion</td>
<td><input type=text name=champion size=20></td>
</tr>
<tr>
<td align=center><input type=submit name=submit value=Simpan></td>
<td align=center><input type=reset name=reset value=Ulangi></td>
</tr>
</table>
</form>
</body>
</html>
Koneksi PHP - MySQL
Koneksi PHP - MySQL
Untuk menyimpan input ke tabel MySQL,
terlebih dahulu input dibaca sesuai metode
yang digunakan.
Untuk menyimpan ke database digunakan
perintah:
$hasil = mysql_query(”SQL Statement”);
Koneksi PHP - MySQL
<?
$sambung = mysql_connect("localhost","root","");
mysql_select_db(dbbola,$sambung) or die("Koneksi ke dbbola gagal");
?>
<html>
<head>
<title>Simpan Liga</title>
Skrip – Simpan Data
<meta author=Soe>
</head>
<body>
<h1>Data Barang</h1>
<?
$kode = $_POST[kode];
$negara = $_POST[negara];
$champion = $_POST[champion];
?>
Koneksi PHP - MySQL
<?
$q_simpan = "insert into Liga values('$kode' ,'$negara','$champion')";
$hasil = mysql_query($q_simpan,$sambung);
Skrip – Simpan Data
if($hasil){
echo "Data tersimpan: <br>";
echo "Kode
: ".$kode."<br>";
echo "Negara
: ".$negara."<br>";
echo "Champion
: ".$champion."<br>";
}else{
echo "Data gagal disimpan";}
?>
<form method=post action=frm_input_Liga.php>
<input type=submit value=Kembali>
</form>
</body>
</html>
Koneksi PHP - MySQL
Koneksi PHP - MySQL
<?
$tampil = "select * from Liga";
$q_buat = mysql_query($tampil,$sambung);
?>
<table border=1>
<tr>
Skrip – Menampilkan
<td>Kode</td>
<td>Negara</td>
<td>Champion</td>
</tr>
<?
while($row = mysql_fetch_row($q_buat)){
echo ("<tr align=center><td>$row[0]</td>");
echo ("<td>$row[1]</td>");
echo ("<td>$row[2]</td></tr>");
}
?>
</table>
<?
//<form method=post action=edit.php><input type=submit value=Edit
name=edit></form>
//<form method=post action=tambah.php><input type=submit value=Tambah
name=tambah></form>
?>
Data
Koneksi PHP - MySQL
Koneksi PHP - MySQL
Form Pencarian
Buat Input dengan type radio untuk
memilih field pencarian.
Buat Input dengan type text sebagai kata
kunci pencarian.
Buat tombol Cari, Input -> type Submit
Koneksi PHP - MySQL
<HTML>
Form - Search
<HEAD>
<title>Cari Database</title>
</HEAD>
<BODY>
<h1>Searching Liga untuk database MySQL</h1>
<form action="hasilsearch.php" method="post">
<select name="kolom">
<option value="kode">Kode</option>
<option value="negara">Negara</option>
</select>
Masukkan kata yang anda cari
<input type ="text" type ="text" name="cari">
<input type ="submit" value="cari" >
</form>
</BODY>
</HTML>
Koneksi PHP - MySQL
Koneksi PHP - MySQL
<?
Skrip Search
$kolom=$_POST['kolom'];
$cari=$_POST['cari'];
$conn=mysql_connect("localhost","root","");
mysql_select_db(“dbbola", $conn);
$hasil=mysql_query("select * from Liga where $kolom like '%$cari%'", $conn);
$jumlah=mysql_num_rows($hasil);
echo "<br>";
echo "Ditemukan: $jumlah";
echo "<br>";
while($baris=mysql_fetch_array($hasil))
{
echo "Kode : ";
echo $baris[0];
echo "<br>";
echo "Negara : ";
echo $baris[1];
echo "<br>";
echo "Champion :";
echo $baris[2];
}
?>
Koneksi PHP - MySQL
Contoh Kasus - 1
CREATE TABLE `employee` (
`id` int(12) NOT NULL auto_increment,
`name` varchar(255) NOT NULL,
Nama Database : dbwork
`address` varchar(255) NOT NULL,
Script – Table mahasiswa
`city` varchar(255) NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=7 ;
INSERT INTO `employee` (`id`, `name`, `address`, `city`) VALUES
(1, 'Soe', '10 street dane', 'Pune'),
(2, 'Debie', '12907A 53 St NW', 'Mumbai'),
(3, 'Atika', '3rd Floor, 888 Fort Street', 'Noida'),
(4, 'Widya', 'Sir Frederick W Haultain Building 9811 109 ST NW', 'London'),
(5, 'Danny', 'Suite 303, 13220 St. Albert Trail', 'Sydney'),
(6, 'Yettri', '9700 Jasper Avenue', 'Perth');
Nama File : Config.php
<?
$sDbHost = 'localhost';
$sDbName = ‘dbwork';
$sDbUser = 'root';
$sDbPwd = '';
$dbConn = mysql_connect ($sDbHost, $sDbUser, $sDbPwd)
or die ('MySQL connect failed. ' . mysql_error());
mysql_select_db($sDbName,$dbConn) or die('Cannot
select database. ' . mysql_error());
?>
Nama File : View.php
<html>
<head>
<title>View Records</title>
</head>
<link href="style.css" rel="stylesheet" type="text/css">
<body>
<?php
include('config.php');
$result = mysql_query("SELECT * FROM employee")
or die(mysql_error());
echo "<table border='1' cellpadding='10'>";
echo "<tr>
<th><font color='#FFFF00'>Id</font></th>
<th><font color='#FFFF00'>Name</font></th>
<th><font color='#FFFF00'>Address</font></th>
<th><font color='#FFFF00'>City</font></th>
<th><font color='#FFFF00'>Edit</font></th>
<th><font color='#FFFF00'>Delete</font></th>
</tr>";
Lanjutan Nama File : View.php
while($row = mysql_fetch_array( $result ))
{
echo "<tr>";
echo '<td><b><font color="#663300">' . $row['id'] . '</font></b></td>';
echo '<td><b><font color="#663300">' . $row['name'] . '</font></b></td>';
echo '<td><b><font color="#663300">' . $row['address'] . '</font></b></td>';
echo '<td><b><font color="#663300">' . $row['city'] . '</font></b></td>';
echo '<td><b><font color="#663300"><a href="edit.php?id=' . $row['id'] .
'">Edit</a></font></b></td>';
echo '<td><b><font color="#663300"><a href="delete.php?id=' . $row['id'] .
'">Delete</a></font></b></td>';
echo "</tr>";
}
echo "</table>";
?>
<p><a href="insert.php">Insert new record</a></p>
</body>
</html>
Nama File : Insert.php
<?php
function valid($name, $address,$city, $error)
{
?>
<html>
<head>
<title>Insert Records</title>
</head>
<link href="style.css" rel="stylesheet" type="text/css">
<body>
<?php
if ($error != '')
{
echo '<div style="padding:4px; border:1px solid red; color:red;">'.$error.'</div>';
}
?>
<form action="" method="post">
<table border="1">
<tr>
<td colspan="2"><b><font color='Red'>Insert Records </font></b></td>
</tr>
Lanjutan Nama File : Insert.php
<tr>
<td width="179"><b><font color='#663300'>Name<em>*</em></font></b></td>
<td><label>
<input type="text" name="name" value="<?php echo $name; ?>" />
</label></td>
</tr>
<tr>
<td width="179"><b><font color='#663300'>Address<em>*</em></font></b></td>
<td><label>
<input type="text" name="address" value="<?php echo $address; ?>" />
</label></td>
</tr>
<tr>
<td width="179"><b><font color='#663300'>City<em>*</em></font></b></td>
<td><label>
<input type="text" name="city" value="<?php echo $city; ?>" />
</label></td>
</tr>
Lanjutan Nama File : Insert.php
<tr align="Right">
<td colspan="2"><label>
<input type="submit" name="submit" value="Insert Records">
</label></td>
</tr>
</table>
</form>
</body>
</html>
<?php
}
include('config.php');
if (isset($_POST['submit']))
{
$name = mysql_real_escape_string(htmlspecialchars($_POST['name']));
$address = mysql_real_escape_string(htmlspecialchars($_POST['address']));
$city = mysql_real_escape_string(htmlspecialchars($_POST['city']));
if ($name == '' || $address == '' || $city == '')
{
Lanjutan Nama File : Insert.php
$error = 'Please enter the details!';
valid($name, $address, $city,$error);
}
else
{
mysql_query("INSERT employee SET name='$name', address='$address',
city='$city'")
or die(mysql_error());
header("Location: view.php");
}
}
else
{
valid('','','','');
}
?>
Nama File : Edit.php
<?php
function valid($id, $name, $address,$city, $error)
{
?>
<html>
<head>
<title>Edit Records</title>
</head>
<link href="style.css" rel="stylesheet" type="text/css">
<body>
<?php
if ($error != '')
{
echo '<div style="padding:4px; border:1px solid red; color:red;">'.$error.'</div>';
}
?>
<form action="" method="post">
<input type="hidden" name="id" value="<?php echo $id; ?>"/>
<table border="1">
<tr>
<td colspan="2"><b><font color='Red'>Edit Records </font></b></td>
</tr>
Lanjutan Nama File : Edit.php
<tr>
<td width="179"><b><font color='#663300'>Name<em>*</em></font></b></td>
<td><label>
<input type="text" name="name" value="<?php echo $name; ?>" />
</label></td>
</tr>
<tr>
<td width="179"><b><font color='#663300'>Address<em>*</em></font></b></td>
<td><label>
<input type="text" name="address" value="<?php echo $address; ?>" />
</label></td>
</tr>
<tr>
<td width="179"><b><font color='#663300'>City<em>*</em></font></b></td>
<td><label>
<input type="text" name="city" value="<?php echo $city; ?>" />
</label></td>
</tr>
<tr align="Right">
<td colspan="2"><label>
<input type="submit" name="submit" value="Edit Records">
</label></td>
</tr>
</table>
</form>
</body>
</html>
<?php
Lanjutan Nama File : Edit.php
}
include('config.php');
if (isset($_POST['submit']))
{
if (is_numeric($_POST['id']))
{
$id = $_POST['id'];
$name = mysql_real_escape_string(htmlspecialchars($_POST['name']));
$address = mysql_real_escape_string(htmlspecialchars($_POST['address']));
$city = mysql_real_escape_string(htmlspecialchars($_POST['city']));
if ($name == '' || $address == '' || $city == '')
{
$error = 'ERROR: Please fill in all required fields!';
valid($id, $name, $address,$city, $error);
}
else
{
mysql_query("UPDATE employee SET name='$name', address='$address' ,city='$city' WHERE id='$id'")
or die(mysql_error());
header("Location: view.php");
}
}
else
{
echo 'Error!';
}
}
Lanjutan Nama File : Edit.php
else
{
if (isset($_GET['id']) && is_numeric($_GET['id']) && $_GET['id'] > 0)
{
$id = $_GET['id'];
$result = mysql_query("SELECT * FROM employee WHERE id=$id")
or die(mysql_error());
$row = mysql_fetch_array($result);
if($row)
{
$name = $row['name'];
$address = $row['address'];
$city = $row['city'];
valid($id, $name, $address,$city,'');
}
else
{ echo "No results!"; }
}
else
{ echo 'Error!'; }
}
?>
Nama File : Delete.php
<?php
include('config.php');
if (isset($_GET['id']) && is_numeric($_GET['id']))
{
$id = $_GET['id'];
$result = mysql_query("DELETE FROM employee WHERE id=$id")
or die(mysql_error());
header("Location: view.php");
}
else
{
header("Location: view.php");
}
?>
Nama File : style.css
body {
color:#2e6ab1;
}
table {
border-collapse: collapse;
}
th {
background-color: #2e6ab1;
padding-left: 14px;
padding-right: 8px;
border: 1px solid #969BA5;
text-align:left;
color:#ffffff;
}
td {
background-color: #F0F0F0;
padding-left: 8px;
padding-right: 8px;
padding-top: 2px;
padding-bottom: 2px;
border: 1px solid #969BA5;
color:#2e6ab1;
}
Input, select {
color:#2e6ab1;
}
Contoh Kasus - 2
CREATE TABLE mhs (
NIM varchar(16) NOT NULL default '',
Nama varchar(145) NOT NULL default '',
TglLahir date NOT NULL default '0000-00-00',
Kelas varchar(15) NOT NULL default '',
Jrs char(3) NOT NULL default '',
PRIMARY KEY (NIM),
KEY NIM (NIM)
) TYPE=MyISAM;
Nama Database : dbmhs
Script – Table mahasiswa
INSERT INTO mhs VALUES ('091011152620001', 'Pradani', '1966-07-10', 'SK-4', '262');
INSERT INTO mhs VALUES ('091011152620002', 'Atika', '1966-07-10', 'SK-4', '262');
INSERT INTO mhs VALUES ('091011152620003', 'Danny', '1966-07-10', 'SK-4', '262');
INSERT INTO mhs VALUES ('091011152620004', 'Debie', '1966-07-10', 'SK-4', '262');
INSERT INTO mhs VALUES ('091011152620005', 'Cintya', '1966-07-10', 'SK-4', '262');
INSERT INTO mhs VALUES ('091011152620006', 'Asep', '1966-07-10', 'SK-4', '262');
INSERT INTO mhs VALUES ('091011152620007', 'Joko', '1966-07-10', 'SK-4', '262');
INSERT INTO mhs VALUES ('091011152620008', 'Acong', '1966-07-10', 'SK-4', '262');
INSERT INTO mhs VALUES ('091011152620009', 'Ucok', '1966-07-10', 'SK-4', '262');
INSERT INTO mhs VALUES ('091011152620010', 'Baba', '1966-07-10', 'SK-4', '262');
INSERT INTO mhs VALUES ('091011152620011', 'Khan', '1966-07-10', 'SK-4', '262');
INSERT INTO mhs VALUES ('091011152620012', 'Nere', '1966-07-10', 'SK-4', '262');
INSERT INTO mhs VALUES ('091011152620013', 'Sania', '1966-07-10', 'SK-4', '262');
INSERT INTO mhs VALUES ('091011152620014', 'Riani', '1966-07-10', 'SK-4', '262');
INSERT INTO mhs VALUES ('091011152620015', 'Ryan', '1966-07-10', 'SK-4', '262');
INSERT INTO mhs VALUES ('091011152620016', 'Wilujeng', '1966-07-10', 'SK-4', '262');
Nama File : BrowseMhs.php
?>php
<font color="#FF0000">
<?
$con=mysql_connect("localhost","root","");
$db=mysql_select_db("dbmhs");
$sql="Select * from mhs";
$hasil=mysql_query($sql);
while ($row=mysql_fetch_array($hasil))
{
echo "$row[NIM]-$row[Nama]-$row[TglLahir]- $row[Kelas]$row[Jrs]";
echo "<a href='editmhs.php?NIM=$row[NIM]'> Edit | </a> ";
echo "<a href='deletemhs.php?NIM=$row[NIM]'> Delete</a> <hr>";
}
?>
Nama File : editmhs.php
<?php
$nim=$_REQUEST[NIM];
$con=mysql_connect("localhost","root","");
$db=mysql_select_db("dbmhs");
$sql="Select * from mhs where NIM='$nim' ";
$hasil=mysql_query($sql);
$row=mysql_fetch_array($hasil);
$nama=$row[Nama];
$tgllahir=$row[TglLahir];
$kelas=$row[Kelas];
$jrs=$row[Jrs];
?>
Lanjutan Nama File : editmhs.php
<font color="#FF0000">
<form action="" method="GET">
NIM
<input type="text" name="NIM" value="<? echo $nim; ?> "><br>
Nama
<input type="text" name="Nama" value="<? echo $nama; ?> "><br>
Tanggal Lahir
<input type="text" name="TglLahir" value="<? echo $tgllahir; ?> "><br>
Kelas
<input type="text" name="Kelas" value="<? echo $kelas; ?> "><br>
Jurusan
<input type="text" name="Jrs" value="<? echo $jrs; ?> "><br>
<input type="submit" name="simpan" value="Update">
<input type="reset" name="batal" value="Cancel">
</form>
Lanjutan Nama File : editmhs.php
<?
if ($_REQUEST[simpan]=='Update')
{
echo "Proses Updating..!";
$nim=$_REQUEST[NIM];$nama=$_REQUEST[Nama];
$tgllahir=$_REQUEST[TglLahir];$kelas=$_REQUEST[Kelas];
$jrs=$_REQUEST[Jrs];
$sql="update mhs set NIM='$nim', Nama='$nama', TglLahir='$tgllahir',
Kelas='$kelas', Jrs='$jrs' where NIM='$nim' ";
$hasil=mysql_query($sql);
echo "Berhasil di Update..!";
}
?>
<hr><a href="ListMhs.php">Back</a>
Nama File : deletemhs.php
<?php
$nim=$_REQUEST[NIM];
$con=mysql_connect("localhost","root","");
$db=mysql_select_db("dbmhs");
$sql="Select * from mhs where NIM='$nim' ";
$hasil=mysql_query($sql);
$row=mysql_fetch_array($hasil);
$nama=$row[Nama];
$tgllahir=$row[TglLahir];
$kelas=$row[Kelas];
$jrs=$row[Jrs];
?>
Lanjutan Nama File : deletemhs.php
<font " color="#FF0000">
<form action="" method="GET">
NIM
<input type="text" name="NIM" value="<? echo $nim; ?> "><br>
Nama
<input type="text" name="Nama" value="<? echo $nama; ?> "><br>
Tanggal Lahir
<input type="text" name="TglLahir" value="<? echo $tgllahir; ?> "><br>
Kelas
<input type="text" name="Kelas" value="<? echo $kelas; ?> "><br>
Jurusan
<input type="text" name="Jrs" value="<? echo $jrs; ?> "><br>
<input type="submit" name="simpan" value="Delete">
<input type="reset" name="batal" value="Cancel">
</form>
Lanjutan Nama File : deletemhs.php
<?
if ($_REQUEST[simpan]=='Delete')
{
echo "Proses Deleting..!";
$sql=" delete from mhs where NIM='$nim' ";
$hasil=mysql_query($sql);
echo "Berhasil di Hapus..!";
}
?>
<a href="ListMhs.php">Back</a>
Nama File : menu.php
<p align="left">
<br/>
<?php
echo "<a href=\"addmhs.php\">Add Mhs</a><br/>";
echo "<a href=\"browsemhs.php\">Browse Mhs</a><br/>";
echo "<a href=\"Listmhs.php\">List Mhs</a><br/>";
echo "<a href=\"FormLogin.php\">Exit</a><br/>";
echo "<br/>";
echo "<br/>";
?>
</p>
Nama File : addmhs.php
<?php
$con=mysql_connect("localhost","root",""); <?
if ($_REQUEST[simpan]=='Add')
$db=mysql_select_db("dbmhs");
{
?>
echo "Proses Adding..!";
<font color="#FF0000">
$nim=$_REQUEST[NIM];$nama=$_REQUEST[Nama];
<form action="" method="GET">
NIM
$tgllahir=$_REQUEST[TglLahir];$kelas=$_REQUEST[Kelas];
<input type="text" name="NIM"><br>
$jrs=$_REQUEST[Jrs];
Nama
$sql="Insert into mhs values ('$nim', '$nama', '$tgllahir',
<input type="text" name="Nama"><br>
'$kelas', '$jrs')";
Tanggal Lahir
$hasil=mysql_query($sql);
<input type="text" name="TglLahir"><br>
echo "Berhasil di Disimpan..!";
Kelas
}
<input type="text" name="Kelas"><br>
?>
Jurusan
<hr><a href=“menu.php">Back</a>
<input type="text" name="Jrs"><br>
<input type="submit" name="simpan" value="Add">
<input type="reset" name="batal" value="Cancel">
</form>
Listmhs.php
<font color="#FF0000">
<?
$con=mysql_connect("localhost","root","");
$db=mysql_select_db("dbmhs");
$sql="Select * from mhs";
$hasil=mysql_query($sql);
while ($row=mysql_fetch_array($hasil))
{
echo "$row[NIM]-$row[Nama]-$row[TglLahir]- $row[Kelas]$row[Jrs]<hr>";
}
?>
<a href=“menu.php”>Back</a>
CREATE TABLE mtk (
KodeMK varchar(10) NOT NULL default '',
NamaMK varchar(145) NOT NULL default '',
SKS int,
KodeJrs char(3) NOT NULL default '',
PRIMARY KEY (KodeMK),
KEY KodeMK (KodeMK)
) TYPE=MyISAM;
Script – Table matakuliah
INSERT INTO mtk VALUES ('KKKI12001', 'Pancasila', '2', '263');
INSERT INTO mtk VALUES ('KKKI12002', 'Agama', '2', '263');
INSERT INTO mtk VALUES ('KKKI12003', 'Bahasa Indonesia', '2', '263');
INSERT INTO mtk VALUES ('KKKI12004', 'Kewarganegaraan', '2', '263');
INSERT INTO mtk VALUES ('KKKI12005', 'Etika Profesi', '2', '263');
CREATE TABLE ambilmk
( nim varchar(16) NOT NULL default '',
kodeMK varchar(10) NOT NULL default '',
nilai char(2) defalt NULL,
PRIMARY KEY (nim,kodeMK)
) TYPE=MyISAM;
Script – Table ambilmk
INSERT INTO ambilmk VALUES ('091011152620003', 'KKKI12001', 'A');
INSERT INTO ambilmk VALUES ('091011152620003', 'KKKI12002', 'A');
INSERT INTO ambilmk VALUES ('091011152620003', 'KKKI12003', 'B');
INSERT INTO ambilmk VALUES ('091011152620003', 'KKKI12004', 'A');
INSERT INTO ambilmk VALUES ('091011152620003', 'KKKI12005', 'C');
INSERT INTO ambilmk VALUES ('091011152620016', 'KKKI12002', 'A');
INSERT INTO ambilmk VALUES ('091011152620016', 'KKKI12003', 'B');
INSERT INTO ambilmk VALUES ('091011152620016', 'KKKI12005', 'A');
<font color="#FF0000">
<?
$con=mysql_connect("localhost","root","");
$db=mysql_select_db("dbmhs");
$sql="Select * from mtk";
$hasil=mysql_query($sql);
while ($row=mysql_fetch_array($hasil))
{
echo "$row[KodeMK]-$row[NamaMK]-$row[SKS]-$row[KodeJrs]";
echo "<a href='editmtk.php?KodeMK=$row[KodeMK]'> Edit | </a> ";
echo "<a href='deletemtk.php?KodeMK=$row[KodeMK]'>
Delete</a>
<hr>";
}
?>
Nama File : FormInputkrs.php
<?php
mysql_connect("localhost", "root", "");
mysql_select_db("dbmhs");
$sql="Select * from mhs";
$hasil=mysql_query($sql);
?>
<font size="" color="#FF0000">
<form method="post" action="simpan.php">
Nomor BP :
<select name="nim">
<? while ($row=mysql_fetch_array($hasil))
{
echo "<option value=$row[NIM]>$row[NIM]</option>";
}
echo "</select><br><br>";
$query = "SELECT * FROM mtk";
$hasil = mysql_query($query);
$no = 1;
while ($data = mysql_fetch_array($hasil))
{
echo "<input type='checkbox' value='".$data['KodeMK']."' name='mk".$no."' /> ".$data['KodeMK'].' - '.$data['NamaMK']."<br />";
$no++;
}
?>
<br>
<input type="hidden" name="jumMK" value="<?php echo $no-1; ?>" />
<input type="submit" name="submit" value="Ambil" />
</form>
Nama File : simpan.php
<?php
mysql_connect("localhost", "root", "");
mysql_select_db("dbmhs");
$nim = $_REQUEST['nim'];
$jumMK = $_POST['jumMK'];
for($i = 1; $i <= $jumMK; $i++)
{
$mk = $_POST['mk'.$i];
if (!empty($mk))
{
$query = "INSERT INTO ambilMK VALUES('$nim', '$mk', '-')";
mysql_query($query);
}
}
echo "Terimakasih sudah memilih matakuliah";
?>
FormNilai.php
<?php
header('Content-type:text/vnd.wap.wml');
echo('<?xml version="1.0"?>');
echo('<!DOCTYPE wml PUBLIC "-//WAPFORUM// DTD WML 1.1/EN">');
mysql_connect("localhost", "root", "");
mysql_select_db("dbmhs");
$sql="Select * from mtk";
$hasil=mysql_query($sql);
?>
<card id="KRS" title="Form Nilai">
<font size="" color="#FF0000">
<form method="post" action="simpan1.php">
Nomor BP :
<select name="kodemk">
<? while ($row=mysql_fetch_array($hasil))
{
echo "<option value=$row[KodeMK]>$row[KodeMK]</option>";
}
echo "</select><br><br>";
$query = "SELECT * FROM ambilmk, mhs, mtk
where ambilmk.nim=mhs.NIM and ambilmk.kodeMK=mtk.KodeMK order by mhs.NIM";
$hasil = mysql_query($query);
$no = 1;
</card>
</wml>
while ($data = mysql_fetch_array($hasil))
{
echo "<select name='nl".$no."'>";
echo "<option value='A'>A</option>";
echo "<option value='B'>B</option>";
echo "<option value='C'>C</option>";
echo "<option value='D'>D</option>";
echo "<option value='E'>E</option>";
echo "<option value='TL'>TL</option>";
echo "<input type='hidden' value='".$data['nim']."' name='nim".$no."' />";
echo "<input type='hidden' value='".$data['kodeMK']."' name='mk".$no."' />
".$data['nim'].' - '.$data['NamaMK'].' - '.$data['kodeMK']."<br/>";
$no++;
}
?>
</select>
<br>
<input type="hidden" name="jumMK" value="<?php echo $no-1; ?>" />
<input type="submit" name="submit" value="Ambil" />
</form>
simpan1.php
<?
header('Content-type:text/vnd.wap.wml');
echo('<?xml version="1.0"?>');
echo('<!DOCTYPE wml PUBLIC "-//WAPFORUM// DTD WML 1.1/EN">');
mysql_connect("localhost", "root", "");
mysql_select_db("dbmhs");
$jumMK = $_POST['jumMK'];
for($i = 1; $i <= $jumMK; $i++)
{
$mk = $_REQUEST['mk'.$i];
$nim = $_REQUEST['nim'.$i];
$nl = $_REQUEST['nl'.$i];
if (!empty($mk))
{
$query = "update ambilMK set nilai='$nl' where nim='$nim' and kodeMK='$mk'";
mysql_query($query);
}
}
echo "Terimakasih sudah memilih matakuliah";
?>
Nama File : ListNilai.php
<b><big>DAFTAR NILAI MAHASISWA
<?
$con=mysql_connect("localhost","root","");
$db=mysql_select_db("dbmhs");
$sql="SELECT mhs.NIM, Nama, mtk.KodeMK, NamaMK, SKS, nilai
FROM ambilmk, mhs, mtk where ambilmk.nim=mhs.NIM and
ambilmk.kodeMK=mtk.KodeMK order by mhs.NIM";
$hasil=mysql_query($sql);
$nim='091011152620001';
$bb=0;$tbb=0;$tsks=0;$nu=0;
echo "<font size=-5 color=#FF0000><br><hr>";
while ($row=mysql_fetch_array($hasil))
Lanjutan
Nama
File
:
ListNilai.php
{
$nu++;
if ($nim!=$row[NIM])
{
if ($nu>1)
{
echo "<b>Indek Prestasi :";
echo number_format($ip,2,',','.');
echo "<br><hr>";
$bb=0;$tbb=0;$tsks=0;$nu=0;
}
}
if ($row[nilai]=='A')
$mutu=4;
elseif ($row[nilai]=='B')
$mutu=3;
elseif ($row[nilai]=='C')
$mutu=2;
elseif ($row[nilai]=='D')
$mutu=1;
elseif ($row[nilai]=='E')
$mutu=0;
elseif ($row[nilai]=='TL‘) $mutu='0';
Lanjutan Nama File : ListNilai.php
$bb=$mutu*$row[SKS];
$tsks=$tsks+$row[SKS];
$tbb=$tbb+$bb;
if ($tbb>0)
$ip=$tbb/$tsks;
echo "$row[NIM]-$row[Nama]-$row[KodeMK]-$row[NamaMK]$row[SKS]-$row[nilai]-$mutu-$bb<hr>";
$nim=$row[NIM];
}
echo "<b>Indek Prestasi :";
echo number_format($ip,2,',','.');
echo "<hr>";
?>
Nama File : .php
Nama File : .php
Nama File : .php
Nama File : .php
Nama File : .php
Nama File : .php
Nama File : .php
Nama File : .php
Nama File : .php
Nama File : .php
Nama File : .php
Nama File : .php
Nama File : .php
Nama File : .php
Nama File : .php
Nama File : .php
Nama File : .php
Nama File : .php
Nama File : .php
Nama File : .php
Nama File : .php
Nama File : .php
Nama File : .php
Nama File : .php
Nama File : .php
Nama File : .php
Nama File : .php
Nama File : .php
Nama File : .php
Nama File : .php
Nama File : .php
Nama File : .php
Nama File : .php
Nama File : .php
Nama File : .php
Nama File : .php
Nama File : .php
Nama File : .php
Nama File : .php
Nama File : .php
Nama File : .php
Nama File : .php
Nama File : .php
Nama File : .php
Nama File : .php
Nama File : .php