Pages

Sabtu, 16 Maret 2013

Tugas web programing dengan php

Posted by anes 9:26 AM, under ,,,, | No comments

Malam all....

Sedikit bingung untuk menjelaskan nya ke teman2 jadi saya mencoba membuat tulisan ini semoga bisa lebih membantu teman2 yang sedang belajar php maupun yang lagi di kejar2 tugas web programing :D

Langsung aja masuk ke tugasnya,
1.buat sebuah halaman index sebagai halaman utama,semua proses terjadi di halaman ini.
2.buat sebuah input form yang terkoneksi ke database dengan detail seperti berikut :
  • nama database akademik
  • nama table pemakai
  • field dari table nya (nama,sandi,level)
3.buat sebuah halaman report untuk menampilkan data dari database hasil inputan.

karena sudah jelas database,table dan field2 nya kita buat database nya dahulu.

setelah itu buat file koneksi nya,
berikut code koneksi.php
<?php
$conn1 = mysql_connect('localhost','root','');
$conn2 = mysql_select_db('akademik',$conn1);

?>

di lanjutkan dengan membuat halaman index.php yang menjadi halaman utamanya :
<html>
<head>
<title>Tugas Web Programing</title>
</head> <body>
<table width="1024" height="500" border="1">
<tr>
<td width="300" valign="top"><a href="?hal=daftar">daftar</a>
<br />
<a href="?hal=report">report</a>
</td>
<td valign="top">
<?php
if(isset($_GET['hal'])){
if($_GET['hal'] == "daftar"){
    include"daftar.php";
}else{
    include"report.php";
}}
?>
</td>
</table>
</body>
</html>
di halaman index terdapat potongan php code
 <?php
if(isset($_GET['hal'])){
if($_GET['hal'] == "daftar"){
    include"daftar.php";
}else{
    include"report.php";
}}
?>
ada function include dalam potongan code di atas
 yang berarti ada file yang di include ke dalam halaman index.php

buat halaman daftar.php :
<html>
<head>
</head>
<body>
<form action="do_daftar.php" method="post">
<table>
<tr><td>Nama</td><td><input type="text" name="username"></td></tr>
<tr><td>sandi</td><td><input type="password" name="password"></td></tr>
<tr><td>level</td><td>
<select name="level">
<option value="admin">Admin</option>
<option value="user">User</option></select></td></tr>
<tr><td colspan="2"><input type="submit" value="submit" name="submit"></td></tr>
</table>
</form>
<!-- Code by Yohanes -->
</body>
</html>
 code di atas hanya tampilan dari form daftar saja,sedangkan core nya ada di
<form action="do_daftar.php" method="post">

dari cuplikan code di atas jelas action yang di tuju ke halaman do_daftar.php dengan method post.
untuk itu kita buat file do_action.php sebagai core nya.
<?php
include"koneksi.php";
if(isset($_POST['submit'])){
$username = $_POST['username'];
$password = $_POST['password'];
$level = $_POST['level'];
  $data = mysql_query("INSERT INTO `pemakai` (`nama`,`sandi`,`level`) VALUES ('$username','$password','$level')");
    echo "Berhasil"."<br>";
    echo "<a href='index.php'>Kembali</a>";

}
?>

oke,setelah masalah input beres,kita masuk ke halaman report nya,saya membuat nya dengan nama  report.php
<html>
<head>
<title>Report Tugas</title>
</head>
<body>
<table border="1">
<tr>
<td>Username</td>
<td>Password</td>
<td>Level</td>
</tr>
<?php
include"koneksi.php";
$quee = mysql_query("SELECT*FROM pemakai")or die(mysql_error());
while($data = mysql_fetch_array($quee)){
    echo "<tr>"."<td>".$data['nama']."</td>"."<td>".$data['sandi']."</td>"."<td>".$data['level']."</td>"."</tr>";
}
?>
</table>
</body>
</html>
pastikan semua file yang sudah di buat di simpan di htdocs(saya menggunakan xampp) dan saya gabung menjadi 1 folder dalam folder tugas.



 untuk melihat hasilnya,anda bisa mengakses nya dari browser
http://localhost/tugas/





Selesai sudah tugas web programing nya.
Semoga bisa jalan juga di tempat anda,
bisa di pelajari lagi script di atas dan di modifikasi menjadi lebih baik lagi.
So keep learn and share :)

Selasa, 05 Maret 2013

menampilkan disk space dengan php

Posted by anes 8:06 PM, under ,,, | No comments

hello...
udah lama ga nulis lagi,kali ini saya akan membahas salah satu function php yaitu disk_free_space() dan disk_total_space()

kedua fungsi ini berguna jika anda ingin mengetahui disk space pada hosting anda,berikut ini contoh penerapannya :

 php file :
<?php

/* get disk space free (in bytes) */
$df = disk_free_space("/var/www");
/* and get disk space total (in bytes)  */
$dt = disk_total_space("/var/www");
/* now we calculate the disk space used (in bytes) */
$du = $dt - $df;
/* percentage of disk used - this will be used to also set the width % of the progress bar */
$dp = sprintf('%.2f',($du / $dt) * 100);

/* and we formate the size from bytes to MB, GB, etc. */
$df = formatSize($df);
$du = formatSize($du);
$dt = formatSize($dt);

function formatSize( $bytes )
{
        $types = array( 'B', 'KB', 'MB', 'GB', 'TB' );
        for( $i = 0; $bytes >= 1024 && $i < ( count( $types ) -1 ); $bytes /= 1024, $i++ );
                return( round( $bytes, 2 ) . " " . $types[$i] );
}

?>

css file :
<style type='text/css'>

.progress {
        border: 2px solid #5E96E4;
        height: 32px;
        width: 540px;
        margin: 30px auto;
}
.progress .prgbar {
        background: #A7C6FF;
        width: <?php echo $dp; ?>%;
        position: relative;
        height: 32px;
        z-index: 999;
}
.progress .prgtext {
        color: #286692;
        text-align: center;
        font-size: 13px;
        padding: 9px 0 0;
        width: 540px;
        position: absolute;
        z-index: 1000;
}
.progress .prginfo {
        margin: 3px 0;
}

</style>

html file :
<div class='progress'>
        <div class='prgtext'><?php echo $dp; ?>% Disk Used</div>
        <div class='prgbar'></div>
        <div class='prginfo'>
                <span style='float: left;'><?php echo "$du of $dt used"; ?></span>
                <span style='float: right;'><?php echo "$df of $dt free"; ?></span>
                <span style='clear: both;'></span>
        </div>
</div>
hasil nya adalah :


Oke sekian dan terimakasih :D
next time semoga bisa lebih rutin lagi update nih blog :)