Sabtu, 30 November 2013

pendataan penyakit menggunakan PHP MYSQL.

Kali ini, sayaakan berbagi cara untuk membuat aplikasi berbasis web untuk pendataan penyakit menggunakan PHP MYSQL dan metode CRUD dan Session.
Berikut ini step by step nya:
1. DATABASE
Siapkan XAMPP dan aktifkan Apache Server dan Mysql nya. Lihat gambar dibawah ini:

Setelah itu, masuklah ke dalam phpmyadmin dengan cara mengetikkan localhost/phpmyadmin di kolom pencarian browser yang kita pakai. Lihat gambar:

Setelah itu, buatlah database dengan nama database “penyakit” dan table dengan nama “sakit”.

Selanjutnya buatlah database untuk admin (CRUD Data) dan operator (Read & Search Data). Nama database nya “Login” dan nama table nya “admin” dan “admin2”. Tabel “admin” untuk login admin, table “admin2” untuk login operator nya.

Selanjutnya, buatlah folder untuk menyimpan file (.php) kita di direktori htdocs. Untuk folder, terserah mau membuat folder dengan nama apapun. Untuk contoh, saya membuat folder denan nama “pwd”.

2. KONEKSI
Buatlah file php untuk koneksi ke database penyakit dengan nama koneksi.php dengan source code dibawah ini:
<?php
$host="localhost";
$user="root";
$password="";
$database="penyakit";
$koneksi=mysql_connect($host,$user,$password);
mysql_select_db($database,$koneksi);
//cek koneksi
if($koneksi){
//echo "berhasil koneksi";
}else{
echo "gagal koneksi";
}
?>

Buatlah file php untuk koneksi ke database login dengan nama file koneksi2.php. Source code:
<?php
$host="localhost";
$user="root";
$password="";
$database="login";
$koneksi=mysql_connect($host,$user,$password);
mysql_select_db($database,$koneksi);
//cek koneksi
if($koneksi){
//echo "berhasil koneksi";
}else{
echo "gagal koneksi";
}
?>
3. LOGIN ADMIN
Buatlah form untuk login admin dengan nama file formlogin1.php. Source code:
<form action="login.php" method="post">
<table align="center">
<center><h3>LOGIN ADMIN</center>
<tr>
<td>Username</td>
<td><input type="text" name="username" size="20"></td>
</tr>
<tr>
<td>Password</td>
<td><input type="password" name="password" size="20"></td>
</tr>
<tr>
<td>&nbsp;</td>
<td><input type="submit" name="Login" value="Proses"></td>
</tr>
</table>
</form>
Hasil tampilan form login untuk admin:

Selanjutnya buatlah file php dengan nama login.php. Source code:
<?php session_start();
include "koneksi2.php";
$username=$_POST['username'];
$password=$_POST['password'];
$query=mysql_query("select * from admin where username='$username' and password='$password'");
$cek=mysql_num_rows($query);
if($cek){
$_SESSION['user']=$user;
?>Anda berhasil login. silahkan menuju <a href="index.php">Halaman ADMIN</a><?php
}else{
?>Anda gagal login. silahkan <a href="formlogin1.php">Login kembali</a><?php
echo mysql_error();
}
?>
4. LOGIN OPERATOR
Buatlah file php dengan nama formlogin2.php. Source code:
<form action="login2.php" method="post">
<table align="center">
<center><h3>LOGIN PETUGAS</center>
<tr>
<td>Username</td>
<td><input type="text" name="username" size="20"></td>
</tr>
<tr>
<td>Password</td>
<td><input type="password" name="password" size="20"></td>
</tr>
<tr>
<td>&nbsp;</td>
<td><input type="submit" name="Login" value="Proses"></td>
</tr>
</table>
</form>
Buatlah file php dengan nama login2.php. Source code:
<?php session_start();
include "koneksi2.php";
$username=$_POST['username'];
$password=$_POST['password'];
$query=mysql_query("select * from admin2 where username='$username' and password='$password'");
$cek=mysql_num_rows($query);
if($cek){
$_SESSION['user']=$user;
?>Anda berhasil login. silahkan menuju <a href="formcari.php">Halaman PETUGAS</a><?php
}else{
?>Anda gagal login. silahkan <a href="formlogin2.php">Login kembali</a><?php
echo mysql_error();
}
?>
5. INSERT DATA
Buatlah form untuk menginputkan data dengan nama file add.html
Source code:
<form action="insert.php" method="post">
<table>
<tr>
<td>Kode Penyakit</td> <td>:<input name='kode' type='text'></td>
</tr>
<tr>
<td>Nama Penyakit</td> <td>:<input name='nama' type='text'></td>
</tr>
<tr>
<td>Definisi Penyakit</td> <td>:<input name='definisi' type='text'></td>
</tr>
<tr>
<td colspan=2><input type='submit' value='SIMPAN'></td>
</tr>
</table>
</form>
Selanjutnya buatlah file php dengan nama file insert.php. Source code:
<?php
$con=mysqli_connect("localhost","root","","penyakit");
// Check connection
if (mysqli_connect_errno())
  {
  echo "Failed to connect to MySQL: " . mysqli_connect_error();
  }

$sql="INSERT INTO sakit (kode, nama, definisi)
VALUES
('$_POST[kode]','$_POST[nama]','$_POST[definisi]')";

if (!mysqli_query($con,$sql))
  {
  die('Error: ' . mysqli_error($con));
  }
echo "1 record added";

mysqli_close($con);
header('location:index.php');
?>
5. MENAMPILKAN DATA (SELECT/READ)
Buatlah file php dengan nama file index.php untuk menampilkan data. Source code:
<?php
 $sambung = mysql_connect("localhost", "root", "") or die ("Gagal konek ke server.");
mysql_select_db("penyakit") or die ("Gagal membuka database.");
?>
<table align="center" border="5">
<center> DAFTAR PENYAKIT </center>;
<tr>
<th>KODE</th>
<th>Nama Penyakit</th>
<th>Definisi</th>
<th colspan="3">Aksi</th>
</tr>
<?php
$query = "select * from sakit";
$result = mysql_query($query, $sambung);
//$no = 0;
while ($buff = mysql_fetch_array($result)){
//$no++;
?>
 <tr>
 <td><?php echo $buff['kode']; ?></td>
 <td><?php echo $buff['nama']; ?></td>
 <td><?php echo $buff['definisi']; ?></td>
 <td><a href="editan.php?kode=<?php echo $buff['kode']; ?>">Edit</a> |
  <td><a href="delete.php?kode=<?php echo $buff['kode']; ?>">Hapus</a>
 </tr>
 <?php
};
mysql_close($sambung);
?>
</table>
<p align="center"><a href="add.html">Tambah Data</a></p>
Tampilan:

6. HAPUS DATA (DELETE)
Buatlah file php dengan nama file delete.php untuk menghapus data. Source code:
<?php
include "koneksi.php";
mysql_query("delete from sakit where kode='$_GET[kode]'");
header('location:index.php');
?>
7. EDIT DATA (UPDATE)
Buatlah file dengan nama editan.php untuk mengedit data. Source code:
<?php
 $sambung = mysql_connect("localhost", "root", "") or die ("Gagal konek ke server.");
mysql_select_db("penyakit") or die ("Gagal membuka database.");
//$edit=mysql_query("SELECT * FROM mhs WHERE nim='$_GET[nim]'");
//$r_edit=mysql_fetch_array($edit);
$kode = $_GET['kode'];
$query = "select * from sakit where kode='$kode'";
$result =  mysql_query($query, $sambung) or die("gagal melakukan query");
     $buff = mysql_fetch_array($result);
                 mysql_close($sambung);
?>
<html>
<head><title>Edit Data</title></head>
<body>
<form name="form1" method="post" action="edit.php">
<table>
<tr>
<td>Kode</td><td><input type="text" name="kode" value="<?php echo $buff['kode']; ?>"></td></tr>
<tr><td>Nama</td><td><input type="text" name="nama" value="<?php echo $buff['nama']; ?>"></td></tr>
<tr><td>Definisi</td><td><input type="text" name="definisi" value="<?php echo $buff['definisi']; ?>" size="50"></td></tr>
<tr>
<input value="Simpan" type="submit" name="submit"/>
<input type="button" value="Kembali" onClick="self.history.back()"></td></tr>
</table>
</form>
</body>
</html>
Selanjutnya buatlah file php dengan nama edit.php. Source code:
<?php
include("koneksi.php");
   $kode = $_POST['kode'];
     $nama = $_POST['nama'];
     $definisi = $_POST['definisi'];
                 $query = mysql_query("update sakit set nama='$nama', nama='$nama', definisi='$definisi' where kode='$kode'");
header('location:index.php');
?>
Tampilan edit data:

7. MENCARI DATA
Buatlah file php dengan nama file formcari.php untuk menampilkan data yang akan dicari. Source code:
<?php
 $sambung = mysql_connect("localhost", "root", "") or die ("Gagal konek ke server.");
mysql_select_db("penyakit") or die ("Gagal membuka database.");
?>
<table align="center" border="5">
<center> DAFTAR PENYAKIT </center>;
<tr>
<th>KODE</th>
<th>Nama Penyakit</th>
<th>Definisi</th>
<th colspan="3">Aksi</th>
</tr>
<?php
$query = "select * from sakit";
$result = mysql_query($query, $sambung);
//$no = 0;
while ($buff = mysql_fetch_array($result)){
//$no++;
?>
 <tr>
 <td><?php echo $buff['kode']; ?></td>
 <td><?php echo $buff['nama']; ?></td>
 <td><?php echo $buff['definisi']; ?></td>
 <td><a href="editan.php?kode=<?php echo $buff['kode']; ?>">Edit</a> |
  <td><a href="delete.php?kode=<?php echo $buff['kode']; ?>">Hapus</a>
 </tr>
 <?php
};
mysql_close($sambung);
?>
</table>
<form name="formcari" method="post" action="search_exe.php">
<table width="330" border="0" align="center" cellpadding="0">

<tr> <td>  Nama Penyakit </td>
<td> <input type="text" name="name"> </td>
</tr>
<td></td>
<td> <input type="SUBMIT" name="SUBMIT" id="SUBMIT" value="search" > </td>
</table>
</form>
Buatlah file php dengan nama file search-exe.php. Source code:
<?php
include "koneksi.php";
$name= $_POST['name']; //get the nama value from form
$q = "SELECT * from sakit where nama like '%$name%' "; //query to get the search result
$result = mysql_query($q); //execute the query $q
echo "<center>";
echo "<h2> Hasil Pencarian </h2>";
echo "<table border='1' cellpadding='5' cellspacing='8'>";
echo "
<tr bgcolor='orange'>
<td>Kode</td>
<td>Nama Penyakit</td>
<td>Definisi</td>
</tr>";
while ($data = mysql_fetch_array($result)) {  //fetch the result from query into an array
echo "
<tr>
<td>".$data['kode']."</td>
<td>".$data['nama']."</td>
<td>".$data['definisi']."</td>
</tr>";
}
echo "</table>";
?>
<p align="center"><a href="formcari.php">KEMBALI</a></p>
Tampilan pencarian data:






Selasa, 08 Oktober 2013

TUGAS 2 PEMROGRAMAN WEB DINAMIS

1. Database

2. Koneksi
3. Login


4. Halaman Admin

5. Input Data



6.Tampil



 7. Edit Update



8. Delete
9. Tampilan Halaman User



10. Logout






Jumat, 04 Oktober 2013

TUGAS PEMROGRAMAN WEB DINAMIS

1. koneksi.php


2. Database
3. isi_form.php

4, daftar_data.php
 
5. hapus_penyakit.php
 



Sabtu, 06 Oktober 2012

link list


LINK LIST

1. Menambah di depan
void insertDepan(int databaru){
TNode *baru,*bantu;
baru = new TNode;
baru->data = databaru;
baru->next = baru;
if(isEmpty()==1){
head=baru;
head->next=head;
}
else {
bantu = head;
while(bantu->next!=head){
bantu=bantu->next;
}
baru->next = head;
head = baru;
bantu->next = head;
}
printf(”Data masuk\n“);
}


2. Menambah elemen dibelakang
void insertBelakang (int databaru){
TNode *baru,*bantu;
baru = new TNode;
baru->data = databaru;
baru->next = baru;
if(isEmpty()==1){
head=baru;
head->next=head;
}
else {
bantu = head;
while(bantu->next != head){
bantu=bantu->next;
}
bantu->next = baru;
baru->next = head;
}
printf(”Data masuk\n“);
}

3. Menghapus elemen di depan
void hapusDepan (){
TNode *hapus,*bantu;
if (isEmpty()==0){
int d;
hapus = head;
d = head->data;
if(head->next != head){
bantu = head;
while(bantu->next!=head){
bantu=bantu->next;
}
head = head->next;
delete hapus;
bantu->next = head;
}else{
head=NULL;
}
printf(“%d terhapus\n“,d);
} else printf(”Masih kosong\n“);
}

4. Menghapus elemen dibelakang
void hapusBelakang(){
TNode *hapus,*bantu;
if (isEmpty()==0){
int d;
hapus = head;
if(head->next == head){
head = NULL;
}else{
bantu = head;
while(bantu->next->next != head){
bantu = bantu->next;
}
hapus = bantu->next;
d = bantu->data;
bantu->next = head;
delete hapus;
}
printf(“%d terhapus\n“,d);
} else printf(”Masih kosong\n“);
}

5. Mencari elemen
Ketemu  = false;
N=1;
While ((N<ukuran) and (not ketemu)) do
If (array[n]=kunci)then
Ketemu = true {data ketemu}
i = n {pada posisi ke – i}
end if
else n = n+1 {cek data berikutnya}
end while
if ketemu then pencarianLinier = I {data ketemu pada posisi ke-i}
else pencarianLinier = -1 {data tidak ketemu}
end if 

program


#include <cstdlib>
#include <iostream>

using namespace std;

class hit{
      private:
              double s,l,p,t,luba,voba,luku,voku;
              double as,ts,tp,lp,vp,ls,ks;
              double pi,r,vobo,lubo;
      public:
             double lubaku();
             double lupris();
             double lubol();
             };
           
double hit::lubaku(){
    cout<<"input lebar:";
    cin>>l;
    cout<<"input panjang:";
    cin>>p;
    cout<<"input tinggi:";
    cin>>t;
    cout<<"input sisi kubus:";
    cin>>s;
    luba=2*((p*l)+(p*t)+(l*t));
    voba=p*l*t;
    luku=6*(s*s);
    voku=s*s*s;
    cout<<"Volum Kubus: "<<voku<<endl;
    cout<<"Volume Balok: "<<voba<<endl;
    cout<<"Luas Permukaan Kubus: "<<luku<<endl;
    cout<<"Luas Permukaan Balok: "<<luba<<endl;
    cout<<endl;
    }
   
double hit::lupris(){
    cout<<"input alas segitiga: ";
    cin>>as;
    cout<<"input tinggi segitiga: ";
    cin>>ts;
    cout<<"input tinggi prisma: ";
    cin>>tp;
    ls=0.5*(as*ts);
    ks=(2*ts)+as;
    lp=(2*ls)+(ks*tp);
    vp=ls*ts;
    cout<<"Volume Prisma: "<<vp<<endl;
    cout<<"Luas Permukaan Prisma: "<<lp<<endl;
    cout<<endl;
}

double hit::lubol(){
       cout<<"input jari-jari: ";
       cin>>r;
       pi=3.14;
       lubo=4*pi*(r*r);
       vobo=pi*(r*r*r);
       cout<<"Luas Permukaan Bola: "<<lubo<<endl;
       cout<<"Volume Bola: "<<vobo<<endl;
       cout<<endl;
       }

   
int main(int argc, char *argv[])
{
    hit c;
    c.lubaku();
    c.lupris();
    c.lubol();
    system("PAUSE");
    return EXIT_SUCCESS;
}

.Subprogram x pangkat n dengan cara rekursif




If (n=0) or (n-1) then factorial = 1
Else factorial = n*factorial(n-1)

Fungsi iteratif dan rekursif untuk menghitung jumlah deret 1, 3, 7, 15, 31, . . . (rumus=L(n) = 2*L(n-1) +1)




·         Rekursif

#include <iostream.h>
Long L(Int n)
{ if ((n==0 || (n==1)) return(1);
Else return (n*L(n-1)+1);
}

main (){
int n;
long hasil;
cout<<”input n:”;
cin>>n;
hasil=L(n);
cout<<”Nilai”<<n<<”!=”<<hasil;
return 0;
}

Mencetak bilangan 1-10 secara Iteratif & Rekursif



·         iteratif

#include <iostream.h>
Main(){
Int I;
For(i=1;i<=10;i++)
Cout<<” “<<i;
Return 0;
}

fibonanci rekursih dan iteratif

fibonanci rekursif


#include <cstdlib>
#include <iostream>

using namespace std;

int recursiveFibo (int n)
{
if (n == 1 || n == 2)
return 1;
else
return recursiveFibo(n-1) + recursiveFibo(n-2);
}



fibonanci iteratif

#include <cstdlib>
#include <iostream>

using namespace std;

int iterativeFibo (int n)
{
if (n == 1 && n == 2)
return 1;
else
{
int f1 = 1;
int f2 = 1;

int fn;

for (int i = 3; i <= n; i++)
{
fn = f1 + f2;
f1 = f2;
f2 = fn;
}

return fn;
}
}
    //system("PAUSE");
    //return EXIT_SUCCESS;
//}

Rabu, 19 September 2012

Contoh Program menggunakan Struct + Class (C++)


#include <iostream>
#include <string>

using namespace std;
class beda{
      struct xxx{
             int p;
             int l;
             };
      public:
             xxx x;
             int rumus();
};
   
int beda::rumus(){
   cout<<"Membedakan Persegi atau Persegi Panjang"<<endl;
   cout<<"Masukan Panjang sisi: ";
   cin>>x.p;
   cout<<"Masukan Lebar sisi: ";
   cin>>x.l;
   if(x.p==x.l)
   {cout<<"Merupakan Persegi"<<endl;}
   else {cout<<"Merupakan Persegi Panjang"<<endl;}
     
}
int main()
{
   beda z;
   z.rumus();

 
   system ("pause");
 
   return 0;
}

Refleksi Struktur data temu 02

Dalam pertemuan kedua, membahas materi Struct dan Class. Sudah bisa memahami karakteristik struct, perbedaan struct dan class. Tapi masih belum bisa membuat program yang didalamnya terdapat struct dan class. Masih perlu bimbingan lagi dari mentor, dosen maupun teman-teman peserta SDATA untuk bisa membuat program menggunakan struct dan class.

Kesimpulan (Materi temu 02 yang saya pahami):

1. Karakteristik Struct:
Struct adalah tipe data yang berisi kumpulan variabel yang sama dan memiliki kaitan satu sama lain.Struct bisa memiliki variabel yang memiliki tipe data sama atau berbeda. Bahkan bisa menyimpan variabel yang bertipe data array atau struct itu sendiri. Anggota struct disebut elemen struct.

2. Perbedaan Struct dan Class:

– Class adalah sesuatu yang mempunyai data (sifat) dan fungsi (kelakuan) untuk mendeskripsikan suatu objek.
– Struct mendefinisikan tipe data dan memberitahukan kepada Visual C++ untuk memperlakukan koleksi tipe data dasar sebagai satu kesatuan tipe data, yang darinya dapat mendefinisikan variabel dan array variabel.

Selasa, 18 September 2012

Fungsi Fibonaci Iteratif (Uji KOmpetensi 1)

Berikut ini adalah source code fungsi Fibonaci secara iteratif dalam C++:


#include <cstdlib>
#include <iostream>

using namespace std;

int iterativeFibo (int n)
{
if (n == 1 || n == 2)
return 1;
else
{
int f1 = 1;
int f2 = 1;

int fn;

for (int i = 3; i <= n; i++)
{
fn = f1 + f2;
f1 = f2;
f2 = fn;
}

return fn;
}
}

Selasa, 03 Juli 2012

Refleksi minggu ke 14

Pada pertemuan perkuliahan Alpro terkahir ini membahas tentang pekerjaan dan masa depan mahasiswa setelah lulus dengan kemampuan di Teknik Informatika. Intinya bercerita tentang cita-cita gitu lah. Hehehe.
Selain itu juga membahas tentang Tugas Proyek.
Dan materi yg ada dalam perkuliahan terakhir ini adala Array rekursif. Saya masih belum paham tentang Array secara rekursif.

Refleksi minggu ke 12

Pada perkuliahan minggu ke 12 ini, mebahas tentang Searching dan Soritng.
Sorting bisa didefinisikan sebagai proses untuk mengurutkan data yang acak menjadi tersusun teratur mnurut aturan tertentu, diterapkan menggunakan tipe data ARRAY agar pemahaman dan implementasi lebih mudah. Ada 2 jenis pengurutan yaitu Ascending/Naik dan Descending/Tutun.
Metode yang digunakan dalam Sorting:
1. Bubble Sort
2. Selection Sort
3. Shell Sort
4. Quick Sort

Refleksi minggu ke 9

Pada perkuliahan ALpro minggu ke 9 ini membahas tentang penjelasan algoritma pemilahan berbagai iteratif, dan penyortiran secara manual menggunakan tiga metode. Saya masih bingung pada materi ini, harus terus belajar dan berkonsultasi dengan mentor dan temna-teman.

Refleksi Minggu 8 (ARRAY)

Dalam kuliah Alpro minggu 8 ini, materi nya adalah membahas tentang Array. Pada kuliah ini menjelaskan bagaimana cara membangun array satu dimensi dan menghilangkan duplikat data (menghapus duplikat). Dalam materi ini saya masih belum paham sepenuhnya tentang Array.   

Minggu, 10 Juni 2012

Menggeser Ke Kanan Elemen Array



Menggeser elemen Array


1. Menggeser elemen array:
# Geser Ke Kiri:


Selasa, 17 April 2012

Work Related Learning FUNCTION / Subprogram (OBSERVATION OF THE ACTIVITIES AT THE RESTAURANT)

The observation that we do, we obtained the following data:
A. The flow of process activities in a restaurant:
a. Before the restaurant opened, owner of the restaurant to give the task to the managers to manage all employees.
b. Restaurant owner to give money to the treasurer to purchase supplies restaurant (Food, beverage ingredients, and cleaning tools)
c. Managers asked the cleaning services to clean and organize every room in the restaurant.
d. Treasurer buy restaurant equipment.
e. If all the rooms in the restaurant is clean and all equipment is available, the restaurant is ready to open.
f. If there are customers who come then set the vehicle parking attendants customers coming.
g. The customer enters into the restaurant to make a purchase.
h. Customers select their seats are available.
i. The waiter came to seat customers and provide a list of foods and drinks with friendly.
j. Customers choose foods and drinks and then returns a list of food and drink to the waiter.
k. The waiter gave food and beverage menu selected by the customer to the chef.
l. Chef cooking food and beverages selected by the customer.
m. If food and beverages is over cooked the waiters deliver food and drinks to customers.
n. Customers enjoy food and drinks that are served by waiters.
o. If customers are finished eating, the customer to the cashier to pay.
p. Cashier service payments. If the customer's money left over, the cashier will give the remaining money to the customer.
q. Then the customer leaves the restaurant and headed to the parking lot to pick up the vehicle.
r. After the customer left, the waiter took the food and beverage equipment already in use.
s. Waiters deliver the food and beverage equipment that is used to wash the dishes.
t. After the restaurant closed, managers told cleaning service to clean up all the room in a restaurant.
u. In addition, the Treasurer reported the financial results to managers.
v. After that, managers report all the results of the activities in the restaurant to restaurant owner.
B. Type of structure and function of the structure:
1. Owner of the restaurant:
Giving money to the treasurer and told manager to manage all staff in the restaurant.
2. Manager:
a) Manage employees.
b) Organize activities in a restaurant.
3. treasurer:
Managing money and buy all restaurant equipment.
4. chef:
Cook the food and drinks.
5. cashier:
Serving payments from customers.
6. waiter:
a) Deliver a list of foods and beverages to customers.
b) Serving food and drinks to customers.
c) Take food and drink equipment that is used by customers and delivered it to the dishwasher.
7. Dishwashers:
Washing eating utensils and drinking that has been used.
8. The cleaners:
Clean and organize every room in the restaurant.
9. Parking attendants:
Set the customer vehicle.