ช่วยดูโด้ให้หน่อยค่ะมันผิดตรงไหนค่ะไม่เข้าใจ..ทำแล้ว function check มันไม่ทำง่นค่ะ ไม่กรอกข้อมูลอะไรข้อความมันไม่เด้งขึ้นมาค่ะ
Code (PHP)
<?php require_once('Connections/dbcon.php'); ?>
<?php
if (!function_exists("GetSQLValueString")) {
function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "")
{
$theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue;
$theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue);
switch ($theType) {
case "text":
$theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
break;
case "long":
case "int":
$theValue = ($theValue != "") ? intval($theValue) : "NULL";
break;
case "double":
$theValue = ($theValue != "") ? "'" . doubleval($theValue) . "'" : "NULL";
break;
case "date":
$theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
break;
case "defined":
$theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue;
break;
}
return $theValue;
}
}
?>
<?php
// *** Validate request to login to this site.
if (!isset($_SESSION)) {
session_start();
}
$loginFormAction = $_SERVER['PHP_SELF'];
if (isset($_GET['accesscheck'])) {
$_SESSION['PrevUrl'] = $_GET['accesscheck'];
}
if (isset($_POST['User'])) {
$loginUsername=$_POST['User'];
$password=$_POST['Pass'];
$MM_fldUserAuthorization = "login_accesslevel";
$MM_redirectLoginSuccess = "u_function.php";
$MM_redirectLoginFailed = "User/u_function.php";
$MM_redirecttoReferrer = true;
mysql_select_db($database_dbcon, $dbcon);
$LoginRS__query=sprintf("SELECT login_user, login_pass, login_accesslevel FROM m_login WHERE login_user=%s AND login_pass=%s",
GetSQLValueString($loginUsername, "text"), GetSQLValueString($password, "text"));
$LoginRS = mysql_query($LoginRS__query, $dbcon) or die(mysql_error());
$loginFoundUser = mysql_num_rows($LoginRS);
if ($loginFoundUser) {
$loginStrGroup = mysql_result($LoginRS,0,'login_accesslevel');
//declare two session variables and assign them
$_SESSION['MM_Username'] = $loginUsername;
$_SESSION['MM_UserGroup'] = $loginStrGroup;
if (isset($_SESSION['PrevUrl']) && true) {
$MM_redirectLoginSuccess = $_SESSION['PrevUrl'];
}
header("Location: " . $MM_redirectLoginSuccess );
}
else {
header("Location: ". $MM_redirectLoginFailed );
}
}
?>
<!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=windows-874" />
<title>Untitled Document</title>
<style type="text/css">
<!--
.style16 {
font-family: "Angsana New";
font-weight: bold;
font-size: 22px;
color: #000000;
}
body {
background-image: url(image/background/original_moonlight-wallpaper-01-1024x768.jpg);
background-repeat: no-repeat;
}
-->
</style>
</head>
<body>
<table width="908" height="808" border="0" align="center" bgcolor="#FFFFFF">
<tr>
<td height="218" valign="top"><img src="image/header/header1_1.jpg" width="900" height="214" /></td>
</tr>
<tr>
<td height="515" align="center" valign="middle">
<form ACTION="<?php echo $loginFormAction; ?>" id="fmLogin" name="fmLogin" method="POST">
<p> </p>
<table width="478" height="304" border="0" align="center">
<tr>
<td valign="middle" background="image/login copy.jpg"><table width="371" border="0" align="center">
<tr>
<td> </td>
<td> </td>
<td> </td>
</tr>
<tr>
<td width="105"> </td>
<td width="144"> </td>
<td width="108"> </td>
</tr>
<tr>
<td align="right"><span class="style16">Username: </span></td>
<td><input name="User" type="text" id="User" /></td>
<td> </td>
</tr>
<tr>
<td align="right"><span class="style16">Password:</span></td>
<td><input name="Pass" type="text" id="Pass" /></td>
<td> </td>
</tr>
<tr>
<td> </td>
<td><input type="submit" name="Submit" id="Submit" value="Login" />
<input type="reset" name="Reset" id="Reset" value="Cancel" /></td>
<td> </td>
</tr>
<tr>
<td> </td>
<td> </td>
<td> </td>
</tr>
<tr>
<td> </td>
<td> </td>
<td> </td>
</tr>
</table></td>
</tr>
</table>
</form>
<script language="javascript">
function check() {
if(document.fmLogin.User.value=="") {
alert("กรุณากรอก Username ด้วยครับ") ;
document.fmLogin.User.focus() ;
return false ;
}
else if(document.fmLogin.Pass.value=="") {
alert("กรุณากรอก Password ด้วยครับ") ;
document.fmLogin.Pass.focus() ;
return false ;
}
else
return true ;
}
</script>
</td>
</tr>
<tr>
<td><img src="image/header/Style7 copy.jpg" width="900" height="65" /></td>
</tr>
</table>
</body>
</html>
//ทำแล้ว function check มันไม่ทำง่นค่ะ ไม่กรอกข้อมูลอะไรข้อความมันไม่เด้งขึ้นมาค่ะTag : PHP, JavaScript
Date :
2012-03-07 20:14:55
By :
Liw
View :
924
Reply :
1
Code (PHP)
input type="submit" name="Submit" id="Submit" value="Login" onClick="return check();" />
แนะนำให้เอา javascript ไปใส่ไว้ภายใต้ <head > ---------------------- </head> นะครับ
Code (JavaScript)
<script language="javascript">
function check() {
if(document.fmLogin.User.value=="") {
alert("กรุณากรอก Username ด้วยครับ") ;
document.fmLogin.User.focus() ;
return false ;
}
else if(document.fmLogin.Pass.value=="") {
alert("กรุณากรอก Password ด้วยครับ") ;
document.fmLogin.Pass.focus() ;
return false ;
}
else
return true ;
}
</script>
Date :
2012-03-07 21:56:03
By :
000su000
Load balance : Server 02