Ketentuan :
a)Tabel yang digunakan adalah salah satu tabel dalam tesisnya masing-masing
b)Gunakan framework yang telah di buat sebelumnya.
<wml>
<card id="satu" title="Login">
<table>
<tr><td>Username </td>
<td><input width="90" height="35"
name="user"/></td></tr>
<tr><td>Password </td>
<td><input type="password" width="90" height="35"
name="pass"/></td></tr>
<anchor>
<go method="post" href="proses_login.php">
<postfield name="userL" value="$(user)"/>
<postfield name="passL" value="$(pass)"/>
</go>
Login
</anchor>
</table>
</card>
</wml>
<?php
echo('<?xml version="1.0"?>');
echo('<!DOCTYPE wml PUBLIC "-//WAPFORUM//DTD WML
1.1/EN">');
?>
<wml>
<card title=".:: Menu Pilihan ::." newcontext="true">
<p align="left">
<small>
<br/>
<?php
echo "<a href=\"addbola.php\">Add Bola</a><br/>";
echo "<a href=\"browsebola.php\">Browse Bola</a><br/>";
echo "<a href=\"ListBola.php\">List Bola</a><br/>";
echo "<a href=\"FormLogin.wml\">LogOut</a><br/>";
echo "<br/>";
echo "<br/>";
?>
</small>
</p>
</card>
</wml>
<wml>
<card id="baca" title="Browse Bola">
<table width="30%" border="1" style="border-collapse:collapse">
<small> <tr bgcolor="#FFFF11"><td colspan="6" align="center">
<b>DAFTAR PERTANDINGAN PIALA PRESIDEN 2018</b></td></tr>
<?php
include_once 'Table.php';
$table = new Table('skor_bola');
$users = $table->findAll();
?>
<tr><td colspan="6" align="center"><a href="AddBola.php"><b>Tambah Data
Bola</b></a></td></tr>
<tr> <th>ID</th> <th>Klub1</th> <th>Klub2</th> <th>Skor</th>
<th>Action</th> </tr>
<?php foreach($users as $user){?>
<tr align="center">
<td><?php echo $user->ID;?> <td><?php echo $user->klub1;?></td>
<td><?php echo $user->klub2?></td> <td><?php echo $user->skor1.":".$user-
>skor1?></td><td>
<a href="EditBola.php?ID=<?php echo $user->ID?>">Edit |</a>
<a href="DeleteBola.php?ID=<?php echo $user->ID?>">Delete</a>
</td> </tr><?php }?> </table> </card>
</wml>
<wml>
<card id="baca" title="Add Bola">
<table width="20%" border="0" style="border-collapse:collapse">
<tr bgcolor="#FFFF11"><td colspan="2" align="center"> TAMBAH DATA BOLA</td></tr>
<?php
if($_POST){
include_once 'Table.php';
$bola = new Table('skor_bola');
try{
$bola->save(array(
'klub1' => $_POST['klub1'],
'klub2' => $_POST['klub2'],
'skor1' => $_POST['skor1'],
'skor2' => $_POST['skor2'],
'ID' => ''
));
header("Location: Contoh-5.php");
exit;
}catch(Exception $e){
echo 'Gagal Menyimpan Data Bola';
echo '<br/>Error: '.$e->getMessage();
}
}
echo "<form action='' method='post'>";
echo "<tr><td>Klub1</td><td><input type='text' height='22' width='75' name='klub1'></td></tr>";
echo "<tr><td>Klub2</td><td><input type='text' height='22' width='75' name='klub2'></td></tr>";
echo "<tr><td>Skor1</td><td><input type='text' height='22' width='75' name='skor1'></td></tr>";
echo "<tr><td>Skor2</td><td><input type='text' height='22' width='75' name='skor2'></td></tr>";
echo "<tr><td colspan=2><input type='submit' name='simpan' value='Add'> ";
echo "<a href='Contoh-5.php'>Cancel</a> ";
echo "</td></tr></form>";
?>
</table>
</card>
</wml>
<?php
include_once 'Table.php';
$brs = new Table('skor_bola');
if($_POST){
try{
$data = array(
'klub1' => $_POST['klub1'],
'klub2' => $_POST['klub2'],
'skor1' => $_POST['skor1'],
'skor2' => $_POST['skor2'],
'ID' => $_POST['ID']
);
$brs->update($data,"ID='$_POST[ID]'");
header("Location: menu.php");
exit;
}catch(Exception $e){
echo 'Gagal Mengedit data Bola';
echo '<br/>Error: '.$e->getMessage();
}
}
$currentbrs = $brs->findBy('ID',$_GET[ID]);
$currentbrs = $currentbrs->current();
?>
<table width="40%" border="0" style="border-collapse:collapse">
<form action="" method="post">
<tr><th colspan=7>EDITING DATA BOLA</th></tr>
<tr><th>ID Bola</th><th><input type="text" name="ID" value="<?php echo $currentbrs->ID;?>" readonly="readonly"/></th></tr>
<tr><th>Nama Klub 1</th><th><input type="text" name="klub1" value="<?php echo $currentbrs->klub1;?>" /></th></tr>
<tr><th>Nama Klub 2</th><th><input type="text" name="klub2" value="<? echo $currentbrs->klub2;?>"/></th></tr>
<tr><th>Skor Klub 1</th><th><input type="text" name="skor1" value="<? echo $currentbrs->skor1;?>"/></th></tr>
<tr><th>Skor Klub 2</th><th><input type="text" name="skor2" value="<? echo $currentbrs->skor2;?>"/></th></tr>
<tr><th><input type="submit" value="Edit"/></th></tr>
</form>
</table>
<?php
include_once 'Table.php';
$brs = new Table('skor_bola');
if($_POST){
try{
$data = array(
'klub1' => $_POST['klub1'],
'klub2' => $_POST['klub2'],
'skor1' => $_POST['skor1'],
'skor2' => $_POST['skor2'],
'ID' => $_POST['ID']
);
$brs->delete("ID='$_POST[ID]'");
header("Location: menu.php");
exit;
}catch(Exception $e){
echo 'Gagal Menghapus data Bola';
echo '<br/>Error: '.$e->getMessage();
}
}
$currentbrs = $brs->findBy('ID',$_GET[ID]);
$currentbrs = $currentbrs->current();
?>
<table width="40%" border="0" style="border-collapse:collapse">
<form action="" method="post">
<tr><th colspan=7>DELETING DATA BOLA</th></tr>
<tr><th>ID Bola</th><th><input type="text" name="ID" value="<?php echo $currentbrs->ID;?>"
readonly="readonly"/></th></tr>
<tr><th>Nama Klub 1</th><th><input type="text" name="klub1" value="<?php echo $currentbrs->klub1;?>"
/></th></tr>
<tr><th>Nama Klub 2</th><th><input type="text" name="klub2" value="<? echo $currentbrs->klub2;?>"/></th></tr>
<tr><th>Skor Klub 1</th><th><input type="text" name="skor1" value="<? echo $currentbrs->skor1;?>"/></th></tr>
<tr><th>Skor Klub 2</th><th><input type="text" name="skor2" value="<? echo $currentbrs->skor2;?>"/></th></tr>
<tr><th><input type="submit" value="Delete"/></th></tr>
</form>
</table>
UTS
Buat Program untuk modul sbb:
1.Login.php
2.menu.php (pilihan 1. Add, 2. Browse, 3. List, 4. LogOut)
3.Browse.php
4.Add.php
5.Edit.php
6.Delete.php
7.List.php
Ketentuan :
a)Tabel yang digunakan adalah salah satu tabel dalam tesisnya masing-masing
b)Gunakan framework yang telah di buat sebelumnya.
Nama File : Config.ini
UTS : (Buat Program untuk modul sbb: tabel yang
;database configuration digunakan adalah salah satu tabel dalam tesisnya)
dbhost="localhost"
dbuser="root" 1. Login.php
2. menu.php (pilihan 1. Add, 2. Browse, 3. List, 4.
dbpassword="" LogOut)
dbname=“databasewap" 3. Browse.php
4. Add.php
5. Edit.php
6. Delete.php
7. List.php
Nama File : Config.php
<?php
class Config {
protected static $_config = array();
public static function getConfig($key){
if(!self::$_config){
$filename =
dirname(__FILE__).DIRECTORY_SEPARATOR.'config.ini';
$config = parse_ini_file($filename);
if(false === $config){
throw new Exception('Gagal membaca file konfigurasi');
}
self::$_config = $config;
}
if(isset(self::$_config[$key])){
return self::$_config[$key];
}
}
}
?>
Nama File : Connect1.php
<?php
include_once dirname(__FILE__).DIRECTORY_SEPARATOR.'Config.php';
class Connect {
protected static $_connection;
public static function getConnection(){
if(!self::$_connection){
$dbhost = Config::getConfig('dbhost');
$dbuser = Config::getConfig('dbuser');
$dbpassword = Config::getConfig('dbpassword');
$dbname = Config::getConfig('dbname');
self::$_connection = @mysql_connect($dbhost, $dbuser, $dbpassword);
if(!self::$_connection){ throw new Exception('Gagal melalukan koneksi ke database. '.mysql_error());
}
$result = @mysql_select_db($dbname, self::$_connection);
if(!$result){ throw new Exception('Koneksi gagal: '.mysql_error());
}
}
return self::$_connection;
}
public static function close(){
if(self::$_connection){
mysql_close(self::$_connection);
}
}
}
?>
Nama File : Table.php
<?php
include_once dirname(__FILE__).DIRECTORY_SEPARATOR.'Connect1.php';
class Table {
protected $_tableName;
function __construct($tableName){
$this->_tableName = $tableName;
}
public function connect(){
return Connect::getConnection();
}
public function close(){
Connect::close();
}
function save(array $data){
$sql = "INSERT INTO `".$this->_tableName."` SET";
foreach($data as $field => $value){
$sql .= " `".$field."`='".mysql_real_escape_string($value, Connect::getConnection())."',";
}
$sql = rtrim($sql, ',');
$result = mysql_query($sql, Connect::getConnection());
if(!$result){
throw new Exception('Gagal menyimpan data ke table '.$this->_tableName.': '.mysql_error());
}
}
Lanjutan Nama File : Table.php
function update(array $data, $where = ''){
$sql = "UPDATE `".$this->_tableName."` SET";
foreach($data as $field => $value){
$sql .= " `".$field."`='".mysql_real_escape_string($value, Connect::getConnection())."',";
}
$sql = rtrim($sql, ',');
if($where){
$sql .= " WHERE ".$where;
}
$result = mysql_query($sql, Connect::getConnection());
if(!$result){
throw new Exception('Gagal mengupdate data table '.$this->_tableName.': '.mysql_error());
}
}
function delete($where = ''){
$sql = "DELETE FROM `".$this->_tableName."`";
if($where){
$sql .= " WHERE ".$where;
}
$result = mysql_query($sql, Connect::getConnection());
if(!$result){
throw new Exception('Gagal menghapus data dari table '.$this->_tableName.': '.mysql_error());
}
}
Lanjutan Nama File : Table.php
function findAll(){
include_once dirname(__FILE__).DIRECTORY_SEPARATOR.'Select.php';
$sql = "SELECT * FROM `".$this->_tableName."`";
return new Select($sql);
}
function next(){
$row = $this->_getRow($this->_pointer);
if($row){
$this->_pointer ++;
}
return $row;
}
function current(){
return $this->_getRow($this->_pointer);
}
function close(){
mysql_free_result($this->_getQuery());
Connect::close();
}
}
?>
Script Tabel User : Nama Tabel user
CREATE TABLE IF NOT EXISTS `user` (
`Id_user` int(11) NOT NULL auto_increment,
`Username` char(45) NOT NULL,
`Password` char(15) default NULL,
`Level` char(15) default NULL,
`email` char(35) default NULL,
PRIMARY KEY (`Id_user`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=1 ;
<?
include 'Table.php';
$table = new Table('user'); // user adalah nama tabel
$table->connect();
$table->save(array(
'user_id' => 'admin',
'nama' => 'Admin',
'password' => '123456',
'tipe' => 'USER'
));
$table->close();
?>
Nama File : Contoh-2.php
<?php
include 'Table.php';
$tabel = new Table('user');
$tabel->connect();
$data = array(
'nama' => 'Administrator',
'password' => 'soe165upi'
);
$tabel->update($data, "user_id='admin'");
$tabel->close();
?>
Nama File : Contoh-3.php
<?
include 'Table.php';
$tabel = new Table('user');
$tabel->connect();
$table->delete("user_id='admin'");
$table->close();
?>
Nama File : Contoh-4.php
<?
$conn = mysql_connect("localhost", "root", "");
mysql_select_db("test", $conn);
$sql = "select * from `user`";
$rs = mysql_query($sql);
while($user = mysql_fetch_object($rs)){
echo $user->nama.'-'.$user->user_id.'-'.$user->password.'-'.$user->tipe;
}
?>
Nama File : Contoh-5.php
<?php
include_once 'Table.php';
$wisata->update($data,"id_wisata='$_POST[id_wisata]'");
header("Location: Index.php");
exit;
}catch(Exception $e){
echo 'Gagal Mengedit data Wisata';
echo '<br/>Error: '.$e->getMessage();
}
}
$currentWisata = $wisata->findBy('id_wisata', $_GET['id_wisata']);
$currentWisata = $currentWisata->current();
?>
Lanjutan Nama File : Edit.php