เกี่ยวกับ responseText รบกวนผู้รู้ด้วยค่ะ
ปัญหา : ที่ if(rt=='y') ค่ะ คือค่าที่ได้จากคำสัั่ง responseText มันไม่ได้มาแค่
y ตัวเดียว แต่มันเอาแท๊กอื่นๆมาด้วนค่ะ มันเลยไม่ตกที่ if นี้ซะที ทำไงดีค่ะ
แก้ไม่ได้ แงๆ
รูปข้างล่างนี่จากการ alert("rt"+rt); ดู
ส่วนโค๊ตค่ะ
<? 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" />
<title>:: NSC AdminLogin ::</title>
<style>
body{
background-color:#FFFFF0;
}
.bglogin{
background-image:url(images/login2.png);
background-repeat:no-repeat;
font-family:Arial, Helvetica, sans-serif;
font-size:14px;
width:300px;
height:150px;
margin-top:-15px;
margin-left:-15px;
padding-top:15px;
float:left;
}
.bgshadowlogin{
background-image:url(images/shadowlogin.png);
background-repeat:no-repeat;
width:300px;
height:150px;
margin-top:10em;
margin-left:20em;
}
.style1 {color: #FF0000}
.style2 {font-size: 18px}
</style>
<script type="text/javascript" src="../js/prototype.js"></script>
<script language="javascript">
function chkLogin(){ //ฟังก์ชันมีการกดปุ่มล๊อคอิน
var chk = Form.serialize('FormAdmin');
var url = "admin_check.php";
url += "?dummy="+(new Date()).getTime();
alert(chk);
new Ajax.Request(url,{method: 'post', parameters:chk, onComplete:chkLoginResult});
}
function chkLoginResult(XMLHttPRequest_Obj){
//alert("XMLHttPRequest_Obj"+XMLHttPRequest_Obj);
var rt = XMLHttPRequest_Obj.responseText;
alert("rt"+rt);
if(rt=="y"){ //ถ้าล๊อคอินสำเร็จ จะให้เปิดเพจใหม่
//window.location = 'register.php';
document.getElementById("alert1").innerHTML = "สามารถเปิดได้";
}else{
document.getElementById("alert1").innerHTML = rt; //แต่ถ้าล๊อคอินไม่สำเร็จให้แจ้งเตือน ปัญหา : ตกมาที่เงื่อนไขนี้หมดเรยค่ะ T^T
}
}
</script>
</head>
<body>
<div id="shadowlogin" class="bgshadowlogin">
<div id="bgloginAdmin" class="bglogin">
<FORM METHOD="POST" ACTION="" id="FormAdmin">
<TABLE WIDTH="266" align="center"class="textH1">
<tr>
<td colspan="2" align="center">
<span class="style2"><strong>:: Admin Login ::</strong></span><br><br>
</td>
</tr>
<TR>
<TD width="105" align="right"><strong>Username</strong><span class="style1">*</span> :</TD>
<TD width="149" align="left"><INPUT NAME="admin" TYPE="text" id="admin" size="12" value="<?=$admin; ?>"></TD>
</TR>
<TR>
<TD align="right"><strong>Password</strong><span class="style1">* </span>:</TD>
<TD align="left"><INPUT NAME="pass" TYPE="password" id="pass" size="12"></TD>
</TR>
<TR>
<TD> </TD>
<TD>
<input name="btLogin" type="button" id="btLogin" OnClick="chkLogin();" value="Login">
</TD>
</TR>
</TABLE>
</FORM>
</div>
</div>
<div id="alert1" align="center">....</div>
</body>
</html>
y ตัวเดียว แต่มันเอาแท๊กอื่นๆมาด้วนค่ะ มันเลยไม่ตกที่ if นี้ซะที ทำไงดีค่ะ
แก้ไม่ได้ แงๆ
รูปข้างล่างนี่จากการ alert("rt"+rt); ดู
ส่วนโค๊ตค่ะ
<? 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" />
<title>:: NSC AdminLogin ::</title>
<style>
body{
background-color:#FFFFF0;
}
.bglogin{
background-image:url(images/login2.png);
background-repeat:no-repeat;
font-family:Arial, Helvetica, sans-serif;
font-size:14px;
width:300px;
height:150px;
margin-top:-15px;
margin-left:-15px;
padding-top:15px;
float:left;
}
.bgshadowlogin{
background-image:url(images/shadowlogin.png);
background-repeat:no-repeat;
width:300px;
height:150px;
margin-top:10em;
margin-left:20em;
}
.style1 {color: #FF0000}
.style2 {font-size: 18px}
</style>
<script type="text/javascript" src="../js/prototype.js"></script>
<script language="javascript">
function chkLogin(){ //ฟังก์ชันมีการกดปุ่มล๊อคอิน
var chk = Form.serialize('FormAdmin');
var url = "admin_check.php";
url += "?dummy="+(new Date()).getTime();
alert(chk);
new Ajax.Request(url,{method: 'post', parameters:chk, onComplete:chkLoginResult});
}
function chkLoginResult(XMLHttPRequest_Obj){
//alert("XMLHttPRequest_Obj"+XMLHttPRequest_Obj);
var rt = XMLHttPRequest_Obj.responseText;
alert("rt"+rt);
if(rt=="y"){ //ถ้าล๊อคอินสำเร็จ จะให้เปิดเพจใหม่
//window.location = 'register.php';
document.getElementById("alert1").innerHTML = "สามารถเปิดได้";
}else{
document.getElementById("alert1").innerHTML = rt; //แต่ถ้าล๊อคอินไม่สำเร็จให้แจ้งเตือน ปัญหา : ตกมาที่เงื่อนไขนี้หมดเรยค่ะ T^T
}
}
</script>
</head>
<body>
<div id="shadowlogin" class="bgshadowlogin">
<div id="bgloginAdmin" class="bglogin">
<FORM METHOD="POST" ACTION="" id="FormAdmin">
<TABLE WIDTH="266" align="center"class="textH1">
<tr>
<td colspan="2" align="center">
<span class="style2"><strong>:: Admin Login ::</strong></span><br><br>
</td>
</tr>
<TR>
<TD width="105" align="right"><strong>Username</strong><span class="style1">*</span> :</TD>
<TD width="149" align="left"><INPUT NAME="admin" TYPE="text" id="admin" size="12" value="<?=$admin; ?>"></TD>
</TR>
<TR>
<TD align="right"><strong>Password</strong><span class="style1">* </span>:</TD>
<TD align="left"><INPUT NAME="pass" TYPE="password" id="pass" size="12"></TD>
</TR>
<TR>
<TD> </TD>
<TD>
<input name="btLogin" type="button" id="btLogin" OnClick="chkLogin();" value="Login">
</TD>
</TR>
</TABLE>
</FORM>
</div>
</div>
<div id="alert1" align="center">....</div>
</body>
</html>
เอาใหม่
ถ้ามั่นใจว่าทุกอย่างถูกต้องแล้ว แต่ยงไม่ได้ให้ลองใส่ header นี้ ไว้บนสุดของโค้ด ดูครับ
header("content-type: text/html; charset=UTF-8");
ขอบคุณค่ะ -/\-
<!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" />
<meta http-equiv="X-UA-Compatible" content="IE=EmulateIE7" />
<title>NSC :: ศูนย์ภาคตะวันตก </title>
<script type="text/javascript" src="../js/script.js"></script>
<script type="text/javascript" src="../js/prototype.js"></script>
<script language="javascript">
function chkLogin(){ //ฟังก์ชันเมื่อมีการล๊อคอิน
var chk = Form.serialize("adminLoginForm");
var url = "admin_check.php";
url += "?dummy="+(new Date()).getTime();
alert(chk);
new Ajax.Request(url,{method: 'post', parameters:chk, onComplete:chkLoginResult});
}
function chkLoginResult(XMLHttPRequest_Obj){
var rt = XMLHttPRequest_Obj.responseText;
alert("rt="+rt);
rt="y";
if(rt=="y"){
//window.location = 'admin_index.php';
document.getElementById("alert1").innerHTML = "เป็นอะไร";
}else if(rt!="y"){
document.getElementById("alert1").innerHTML = rt;
}
}
</script>
<link rel="stylesheet" href="../css/style.css" type="text/css" media="screen" />
<!--[if IE 6]><link rel="stylesheet" href="../css/style.ie6.css" type="text/css" media="screen" /><![endif]-->
</head>
<body>
<div class="PageBackgroundSimpleGradient">
</div>
<div class="Main">
<div class="Sheet">
<div class="Sheet-tl"></div>
<div class="Sheet-tr"><div></div></div>
<div class="Sheet-bl"><div></div></div>
<div class="Sheet-br"><div></div></div>
<div class="Sheet-tc"><div></div></div>
<div class="Sheet-bc"><div></div></div>
<div class="Sheet-cl"><div></div></div>
<div class="Sheet-cr"><div></div></div>
<div class="Sheet-cc"></div>
<div class="Sheet-body">
<div class="Header">
<div class="Header-png"></div>
<div class="Header-jpeg"></div>
<div class="logo">
<h1 id="name-text" class="logo-name"><a href="#">National Software Contest</a></h1>
<div id="slogan-text" class="logo-text">สมองคนไทย ไม่แพ้ชาติใดในโลก</div>
</div>
</div>
<div class="nav">
<ul class="artmenu">
<li>
<a href="#" class=" active"><span><span>Home</span></span></a>
</li>
<li>
<a href="#"><span><span>Categories</span></span></a>
</li>
<li>
<a href="#"><span><span>Archive</span></span></a>
</li>
<li>
<a href="#"><span><span>About</span></span></a>
</li>
</ul>
<div class="l"></div>
<div class="r"><div></div></div>
</div>
<div class="contentLayout">
<div class="sidebar1">
<div class="Block">
<div class="Block-tl"></div>
<div class="Block-tr"><div></div></div>
<div class="Block-bl"><div></div></div>
<div class="Block-br"><div></div></div>
<div class="Block-tc"><div></div></div>
<div class="Block-bc"><div></div></div>
<div class="Block-cl"><div></div></div>
<div class="Block-cr"><div></div></div>
<div class="Block-cc"></div>
<div class="Block-body">
<div class="BlockHeader">
<div class="header-tag-icon">
<div class="BlockHeader-text">
Login
</div>
</div>
<div class="l"></div>
<div class="r"><div></div></div>
</div>
<div class="BlockContent">
<div class="BlockContent-body">
<form method="post" id="adminLoginForm">
<div><div class="form-item">
<label for="edit-name">Username: <span class="form-required" title="This field is required.">*</span></label>
<input type="text" maxlength="60" name="adminname" id="adminname" style="width: 95%;" value="<?=$adminname;?>" />
</div>
<div class="form-item">
<label for="edit-pass">Password: <span class="form-required" title="This field is required.">*</span></label>
<input type="password" name="pass" id="pass" maxlength="60" style="width: 95%;" class="form-text required" />
</div>
<button class="Button" type="submit" name="login" onclick="chkLogin();" value="login">
<span class="btn">
<span class="t">Login</span>
<span class="r"><span></span></span>
<span class="l"></span>
</span>
</button>
<div id="alert1">adsad</div>
<div class="cleared"></div>
</div></form>
</div>
</div>
</div>
</div>
<div class="Block">
<div class="Block-tl"></div>
<div class="Block-tr"><div></div></div>
<div class="Block-bl"><div></div></div>
<div class="Block-br"><div></div></div>
<div class="Block-tc"><div></div></div>
<div class="Block-bc"><div></div></div>
<div class="Block-cl"><div></div></div>
<div class="Block-cr"><div></div></div>
<div class="Block-cc"></div>
<div class="Block-body">
<div class="BlockHeader">
<div class="header-tag-icon">
<div class="BlockHeader-text">
Search
</div>
</div>
<div class="l"></div>
<div class="r"><div></div></div>
</div>
<div class="BlockContent">
<div class="BlockContent-body">
<form method="get" id="searchform">
<input type="text" value="" name="s" id="s" style="width: 95%;" />
<button class="Button" type="submit" name="search">
<span class="btn">
<span class="t">Search</span>
<span class="r"><span></span></span>
<span class="l"></span>
</span>
</button>
</form>
</div>
</div>
</div>
</div>
<div class="Block">
<div class="Block-tl"></div>
<div class="Block-tr"><div></div></div>
<div class="Block-bl"><div></div></div>
<div class="Block-br"><div></div></div>
<div class="Block-tc"><div></div></div>
<div class="Block-bc"><div></div></div>
<div class="Block-cl"><div></div></div>
<div class="Block-cr"><div></div></div>
<div class="Block-cc"></div>
<div class="Block-body">
<div class="BlockHeader">
<div class="header-tag-icon">
<div class="BlockHeader-text">
Menu
</div>
</div>
<div class="l"></div>
<div class="r"><div></div></div>
</div>
<div class="BlockContent">
<div class="BlockContent-body">
<ul>
<li><a href="#" title="All News">All News</a> (50)</li>
<li><a href="#" title="Best of the Year">Best of the Year</a> (4)</li>
<li><a href="#" title="Advices">Advices</a> (24)</li>
<li><a href="#" title="Gadgets">Gadgets</a> (17)</li>
<li><a href="#" title="Photos">Photos</a> (6)</li>
<li><a href="#" title="Uncategorized">Uncategorized</a> (23)</li>
</ul>
</div>
</div>
</div>
</div>
<div class="Block">
<div class="Block-tl"></div>
<div class="Block-tr"><div></div></div>
<div class="Block-bl"><div></div></div>
<div class="Block-br"><div></div></div>
<div class="Block-tc"><div></div></div>
<div class="Block-bc"><div></div></div>
<div class="Block-cl"><div></div></div>
<div class="Block-cr"><div></div></div>
<div class="Block-cc"></div>
<div class="Block-body">
<div class="BlockHeader">
<div class="header-tag-icon">
<div class="BlockHeader-text">
Recent comments
</div>
</div>
<div class="l"></div>
<div class="r"><div></div></div>
</div>
<div class="BlockContent">
<div class="BlockContent-body">
<div class="item-list"><ul><li><a href="#">user's comment</a></li></ul> 1 week 1 hour ago<ul><li><a href="#">admin's comment</a></li></ul> 1 week 1 hour ago</div>
</div>
</div>
</div>
</div>
<div class="Block">
<div class="Block-tl"></div>
<div class="Block-tr"><div></div></div>
<div class="Block-bl"><div></div></div>
<div class="Block-br"><div></div></div>
<div class="Block-tc"><div></div></div>
<div class="Block-bc"><div></div></div>
<div class="Block-cl"><div></div></div>
<div class="Block-cr"><div></div></div>
<div class="Block-cc"></div>
<div class="Block-body">
<div class="BlockHeader">
<div class="header-tag-icon">
<div class="BlockHeader-text">
Who's Online
</div>
</div>
<div class="l"></div>
<div class="r"><div></div></div>
</div>
<div class="BlockContent">
<div class="BlockContent-body">
<div>There are currently <em>1 user</em> and <em>0 guests</em> online.
<br/>Online users<ul><li><a href="#" title="View user profile.">user</a></li></ul></div>
</div>
</div>
</div>
</div>
</div>
<div class="content">
<div class="Post">
<div class="Post-tl"></div>
<div class="Post-tr"><div></div></div>
<div class="Post-bl"><div></div></div>
<div class="Post-br"><div></div></div>
<div class="Post-tc"><div></div></div>
<div class="Post-bc"><div></div></div>
<div class="Post-cl"><div></div></div>
<div class="Post-cr"><div></div></div>
<div class="Post-cc"></div>
<div class="Post-body">
<div class="Post-inner">
<h2 class="PostHeaderIcon-wrapper">
<span class="PostHeader">Text, <a href="#" rel="bookmark" title="Permanent Link to this Post">Link</a>, <a class="visited" href="#" rel="bookmark" title="Visited Hyperlink">Visited</a>, <a class="hovered" href="#" rel="bookmark" title="Hovered Hyperlink">Hovered</a></span>
</h2>
<div class="PostMetadataHeader">
<div class="PostHeaderIcons metadata-icons">
<img class="metadata-icon" src="../images/PostDateIcon.png" width="17" height="18" alt="PostDateIcon" />
October 21st, 2008
| <img class="metadata-icon" src="../images/PostAuthorIcon.png" width="14" height="14" alt="PostAuthorIcon" />
Author: <a href="#" title="View user profile.">user</a>
</div>
</div>
<div class="PostContent">
<img class="article" src="../images/logo.jpg" alt="an image" style="float:left;"/>
<p>Lorem ipsum dolor sit amet, <a href="#" title="link">link</a>, <a class="visited" href="#" title="visited link">visited link</a>,
<a class="hover" href="#" title="hovered link">hovered link</a> consectetuer
adipiscing elit. Quisque sed felis. Aliquam sit amet felis. Mauris semper, velit
sem per laoreet dictum, quam diam dic tum urna, nec placerat elit nisl in quam. Etiam
augue pede, molestie eget, rhoncus at, convallis ut, eros. Nunc iaculis suscipit dui. Nam sit amet sem.
Praesent mattis, massa quis luctus fermentum, turpis mi volutpat justo, eu volutpat enim
diam eget metus. Donec sed tellus eget sapien fringilla
nonummy. <acronym title="National Basketball Association">NBA</acronym> Mauris a
ante. Suspendisse quam sem, consequat at, commodo vitae, feugiat in, nunc. Morbi
imperdiet augue quis tellus.
<abbr title="Avenue">
AVE</abbr></p>
<p>Aliquam pharetra. Nulla in tellus eget odio sagittis blandit.Maecenas at nisl. Nullam lorem mi, eleifend a,
fringilla vel, semper at, ligula. Mauris eu wisi. Ut ante dui, aliquet nec, congue non,
accumsan sit a
นี่โคีต admin_check.php
<? session_start();
//header("content-type: text/html; charset=UTF-8");
$adminname=trim($_POST['adminname']);
$adminPw=trim($_POST['pass']);
if(trim($adminname) == "")
{
echo "กรุณากรอก Username";
exit();
}
if(trim($adminPw) == "")
{
echo "กรุณากรอก Password";
exit();
}
include"../connect.php";
mysql_select_db("db_nsc");
$sql="SELECT * FROM tb_user
WHERE Username = '$adminname' AND Password = '$adminPw' AND Status_user IN ('Admin','SuperAdmin') ";
echo"$sql";
$result=mysql_query($sql) or die ("Error Query");
$member = mysql_fetch_array($result);
if(mysql_num_rows($result)==0){
echo "ERROR : Username หรือ assword ผิด";
}else{
echo"y";
$_SESSION['admin']=$adminname;
session_write_close();
}
mysql_close($cn);
?>
เพราะปุ่ม ดันเป็น type='submit' มันเลยรั่ว