<?php session_start(); ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<script language="javascript">
function checkNull(){ //ชื่อ function ตั้งได้ตามความสดวกของเราได้เลยครับ
var forms=document.form1; //ผมสร้างตัวแปรมาเพื่ออ้างถึง form ครับ
if(forms.user.value == "" ){ //เช็ค if ใน textfile ที่กำหนด ตรง .value == "" คือถ้าเป็นค่า null ก็ให้ทำงานภายใน if นี้.
alert('กรุณากรอก Username'); //สั่งให้ขึ้นข้อความที่ต้องการ
forms.user.focus(); //เพิ่มความฉลาดให้โปรแกรมโดยการให้ cursor วิ่งไปในช่องที่ว่างอยู่
return false; //return false เป็นการไม่ให้โปรแกรมหรือหน้าเว็บเราทำงานต่อ
}
else if (forms.password.value == ""){
alert('กรุณากรอก Password');
forms.password.focus();
return false;
}
}
</script>
<title>Login</title>
<!-- Le styles -->
<link href="css/bootstrap/css/bootstrap.css" rel="stylesheet">
<style type="text/css">
body {
padding-top: 40px;
padding-bottom: 40px;
background-color: #f5f5f5;
}
.form-signin {
max-width: 300px;
padding: 19px 29px 29px;
margin: 0 auto 20px;
background-color: #fff;
border: 1px solid #e5e5e5;
-webkit-border-radius: 5px;
-moz-border-radius: 5px;
border-radius: 5px;
-webkit-box-shadow: 0 1px 2px rgba(0,0,0,.05);
-moz-box-shadow: 0 1px 2px rgba(0,0,0,.05);
box-shadow: 0 1px 2px rgba(0,0,0,.05);
}
.form-signin .form-signin-heading,
.form-signin .checkbox {
margin-bottom: 10px;
}
.form-signin input[type="text"],
.form-signin input[type="password"] {
font-size: 16px;
height: auto;
margin-bottom: 15px;
padding: 7px 9px;
}
</style>
<link href="css/bootstrap/css/bootstrap-responsive.css" rel="stylesheet">
</head>
<body>
<div class="container">
<form class="form-signin" method="post" name="form1" onsubmit="javascript:return checkNull();">
<h1 align="center"> </h1>
<h3 class="form-signin-heading" align="center">หน้า Login โดย</h3>
<p align="center">www.โปรแกรมเมอร์กากกาก.blogspot.com</p>
<input type="text" class="input-block-level" placeholder="User" name="user" id="user">
<input type="password" class="input-block-level" placeholder="Password" name="password" id="password">
<button name="login" id="login" class="btn btn-large btn-block btn-primary" type="submit">เข้าสู่ระบบ</button>
</form>
</div> <!-- /container -->
<?php
if($_POST){
$user = $_REQUEST['user'];
$pw = $_REQUEST['password'];
include("dbconfig.php");
$db=new MYSQL(HOST,USER,PASS,DBNAME);
$db->FIELD = "*";
$db->TABLE = "member WHERE user = '$user' AND password = md5('$pw') ";
$db->SELECT();
if($db->NUM_ROWS() != 1 ){
echo '<div class="alert alert-error" align="center">User หรือ Password ไม่ถูกต้อง</div>';
}else{
if($data = $db->FETCH_ARR()){
$_SESSION['ses_id_member'] = $data['id_member'];
echo '<script type="text/javascript">window.location="index.php";</script>';
}
}exit;
}//end if post
?>
</body>
</html>