 |
|
ผมเขียนโปรแกรมให้มันล็อกอิน แล้วถ้าเราใส่ id ถูกมันจะขึ้นโชวรูปถูก ถ้าผิดมันจะกากบาทครับ โดยดึงข้อมูลมาจากฐานข้อมูล
ตานี้พอใส่ข้อมูลถูกแล้วมันไม่ login เข้าหน้าใหม่ให้ครับ
ช่วยดูโค๊ดให้หน่อยครับ
index.php(PHP)
<form action="index_code.php" name="frmMain" method="post" target="iframe_target">
<iframe id="iframe_target" name="iframe_target" style="width:0;height:0;border:0px solid #fff;" src="#"></iframe>
<script language="JavaScript">/*ulog*/
var HttPRequest = false;
function doCallAjax() {
HttPRequest = false;
if (window.XMLHttpRequest) { // Mozilla, Safari,...
HttPRequest = new XMLHttpRequest();
if (HttPRequest.overrideMimeType) {
HttPRequest.overrideMimeType('text/html');
}
} else if (window.ActiveXObject) { // IE
try {
HttPRequest = new ActiveXObject("Msxml2.XMLHTTP");
} catch (e) {
try {
HttPRequest = new ActiveXObject("Microsoft.XMLHTTP");
} catch (e) {}
}
}
if (!HttPRequest) {
alert('Cannot create XMLHTTP instance');
return false;
}
var url = 'index_code.php';
var pmeters = "ulog=" + encodeURI( document.getElementById("ulog").value);
HttPRequest.open('POST',url,true);
HttPRequest.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
HttPRequest.setRequestHeader("Content-length", pmeters.length);
HttPRequest.setRequestHeader("Connection", "close");
HttPRequest.send(pmeters);
HttPRequest.onreadystatechange = function()
{
if(HttPRequest.readyState == 3) // Loading Request
{
document.getElementById("mySpan").innerHTML = "..";
}
if(HttPRequest.readyState == 4) // Return Request
{
if(HttPRequest.responseText == 'Y')
{
window.location = 'ch.php';
}
else
{
document.getElementById("mySpan").innerHTML = HttPRequest.responseText;
}
}
}
}
</script>
<div id="div_ulog">
<div id="div_u"><input name="ulog" type="text" id="ulog" placeholder="ชื่อผู้ใช้งาน" maxlength="20" OnChange="JavaScript:doCallAjax();"></div>
<div id="mySpan"></div>
<div id="div_p">
<input name="plog" type="password" id="plog" placeholder="รหัสผ่าน" maxlength="14">
</div>
<div id="div_s"><input id="slog" name="slog" type="submit" value="เข้าสู่ระบบ" ></div>
</div>
</form>
index_code.php (PHP)
<?php
session_start();
@ini_set('display_errors', '0');
include('connect.php');
$strulog = trim($_POST["ulog"]);
$strplog = trim($_POST["plog"]);
if(trim($strulog) == "")
{
echo "<img src='img/x.gif'>";
exit();
}
if(isset($_POST['ulog'])){
$sql1 = mysql_query('SELECT * FROM member WHERE u_ser = "'.$strulog .'"');
$result1 = mysql_fetch_array($sql1);
$num1 = mysql_num_rows($sql1);
if($num1<=0){
echo "<img src='img/x.gif'>";
}else{
echo "<img src='img/y.gif'>";
$sql2 = mysql_query('SELECT * FROM member WHERE u_ser = "'.$strulog .'" and p_pass = "'.$strplog .'"');
$result2 = mysql_fetch_array($sql2);
$num2 = mysql_num_rows($sql2);
if($num2<=0){
}else{
if($result1['u_type']== 1){
$_SESSION['user'] = $result1['u_ser'];
$_SESSION['type_id'] = '1';
$_SESSION['mem_id'] = $result1['i_user'];
header("location:ch.php");
}
else{
$_SESSION['user'] = $result1['u_ser'];
$_SESSION['type_id'] = '0';
$_SESSION['mem_id'] = $result1['i_user'];
header("location:ch.php");
}
}
}
}
mysql_close($conn);
?>
Tag : PHP, MySQL, HTML/CSS, Ajax
|
|
 |
 |
 |
 |
Date :
2016-05-23 14:59:37 |
By :
slaparum |
View :
811 |
Reply :
4 |
|
 |
 |
 |
 |
|
|
|
 |