[trick] Membuat Aplikasi Sederhana dengan PHP dan SQL SERVER Bag – 2

Bismillah…

Ok Kali ini Gw Coba Share Tutorial membuat aplikasi sederhana dengan php dan sql server 2000 bagian kedua  >>

yaitu script login,logout dan crud (tambah,edit,hapus,view )…

kalau ketinggalan coba lihat post tentang pembuatan aplikasi sederhana dengan php dan sql server bagian pertama Y…

langsung aja, siapkan databases >>

data_sql

kemudian masukan scriptnya >>

1. form login


<?php
echo"<h3>Form Login</h3><hr><br>
<form method=POST action='cek_login.php'>
<table border=1 cellpadding=4 cellspacing=0>
<tr><td>Nama</td><td><input type=text name='nama'></td></tr>
<tr><td>Password</td><td><input type=password name='password'></td></tr>
<tr><td></td><td><input type=submit value='Login'></td></tr>
</table>
</form>
";
?>

2. cek_login


<?php
mssql_connect("localhost","sa","sa");
mssql_select_db("shoping");

$nama=htmlentities($_POST['nama']);
$password=htmlentities($_POST['password']);

if(!ctype_alnum($nama) or !ctype_alnum($password)){
echo"Login Gagal";
}else{
$sql=mssql_query("select * from [user] where nama LIKE '$nama' and password LIKE '$password'");
$data=mssql_fetch_array($sql);
$cek=mssql_num_rows($sql);
if($cek>0){
session_register('id');
session_register('nama');

$_SESSION['id']=$data['id'];
$_SESSION['nama']=$data['nama'];

header('location:sql_server.php');

}else{
echo"Login GagalL";
}
}
?>

3. home.php atau sql_server.php


<?php
session_start();
mssql_connect("localhost","sa","sa");
mssql_select_db("shoping");

$id=$_SESSION['id'];
$nama=$_SESSION['nama'];

echo"<h3>SELAMAT DATANG | ($nama) dan ID ANDA = $id </h3><hr><p></p>";

if($_GET['menu']==''){
echo"<a href='?menu=tambah_user'><input type=submit value='Tambah'></a><p></p><p></p><table border=1 cellpadding=4 cellspacing=0>
<tr bgcolor='#ccc'><td>Id</td><td>Nama</td><td>Email</td><td>Edit</td><td>Hapus</td></tr>";
$sql=mssql_query("select * from [user]");
while($data=mssql_fetch_array($sql)){
echo"<tr><td>$data[id]</td><td>$data[nama]</td><td>$data[email]</td><td><a href='?menu=edit_user&id=$data[id]'>edit</a></td><td><a href=\"aksi.php?act=hapus_user&id=$data[id]\" onclick=\"return confirm('Yakin Mau Hapus $data[nama] ??')\">hapus</a></td></tr>";
}
echo"</table>";

}if($_GET['menu']=='edit_user'){
$data=mssql_fetch_array(mssql_query("select * from [user] where id = '$_GET[id]'"));
echo"
<form method=POST action='aksi.php?act=edit_user'>
<input type=hidden name='id' value='$data[id]'>
<table border=1 cellpadding=4 cellspacing=0>
<tr><td>Id</td><td><input type=text name='id' value='$data[id]' size=1 disabled></td></tr>
<tr><td>Nama</td><td><input type=text name='nama' value='$data[nama]'></td></tr>
<tr><td>Email</td><td><input type=text name='email' value='$data[email]'></td></tr>
<tr><td>Password</td><td><input type=text name='password' value='$data[password]'></td></tr>
<tr><td></td><td><input type=submit value='Update'></td></tr>
</table>
</form>
";
}

if($_GET['menu']=='tambah_user'){
echo"
<form method=POST action='aksi.php?act=tambah_user'>
<table border=1 cellpadding=4 cellspacing=0>
<tr><td>Id</td><td><input type=text name='id' size=1></td></tr>
<tr><td>Nama</td><td><input type=text name='nama'></td></tr>
<tr><td>Email</td><td><input type=text name='email'></td></tr>
<tr><td>Password</td><td><input type=text name='password'></td></tr>
<tr><td></td><td><input type=submit value='Tambah'></td></tr>
</table>
</form>
";
}

echo"<br> <a href=\"logout.php\" onclick=\"return confirm('Yakin Mau Keluar ??');\">logout</a>";
?>

4. aksi.php


<?php
session_start();
mssql_connect("localhost","sa","sa");
mssql_select_db("shoping");

$act=$_GET['act'];

if($act=='edit_user'){
mssql_query("update [user] set nama='$_POST[nama]',email='$_POST[email]',password='$_POST[password]' where id = '$_POST[id]'");
header('location:sql_server.php');
}

if($act=='tambah_user'){
mssql_query("insert into [user] (id,nama,email,password) values ('$_POST[id]','$_POST[nama]','$_POST[email]','$_POST[password]') ");
header('location:sql_server.php');
}

if($act=='hapus_user'){
mssql_query("delete from [user] where id = '$_GET[id]'");
header('location:sql_server.php');
}

?>

5. logout.php


<?php
session_start();
session_destroy();
header('location:form_login.php');
?>

dan hasil tampilannya seperti ini >>

hasil_sql

OK selesai

untuk download script >> http://www.4shared.com/zip/4Tb4vVIf/sql_server_2.html

Leave a comment

5 Comments

  1. Agung Wahyudi

     /  01/02/2013

    Kok selalu gagal yaaa login….
    Tp trims deh udah berbagi info query nyaaa…🙂

    Reply
    • Cong

       /  22/08/2013

      Disini tidak dijelaskan cara koneksinya pake ODBC atau MSSQL. Makanya gagal loginnya ehehehe…

      Reply
      • @cong coba dilihat aja gan bagian part 1 dari sql server, ada kok :
        [trick] Membuat Aplikasi Sederhana Dengan PHP dan SQL SERVER 2000

  2. untuk menyertakan md5 gimana ya gan..

    info dong ya.

    Reply
  3. Ane nyoba gagal mele gan… mau nambaihn database di SQL Server gimana ya? Ga familiar bgt sama SQL Server nih, tp dipaksa belajar lg…😥

    ________________________________________________
    Jual Mesin Fotocopy Murah

    Reply

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: