昨天JS还能调用 今天突然没办法调用了 求教
<?php
//include('yanzhengma.php');
//require_once('common.php'); // 引入公共文件,其中实现了SQL注入漏洞检查的代码
$username = trim($_POST['username']);
//echo $username;
// 取得客户端提交的密码并用md5()函数时行加密转换以便后面的验证
$pwd = md5($_POST['pwd']);
// 设置一个错误消息变量,以便判断是否有错误发生
// 以及在客户端显示错误消息。 其初值为空
$errmsg = '';
if (!empty($username)) { // 用户填写了数据才执行数据库操作
//---------------------
// 数据验证, empty()函数判断变量内容是否为空
if (empty($username)) {
$errmsg = '数据输入不完整';
}
//---------------------
if(empty($errmsg)) { // $errmsg为空说明前面的验证通过
// 调用mysqli的构造函数建立连接,同时选择使用数据库'test'
$db = @new mysqli("localhost", "root", "", "test");
// 检查数据库连接
if (mysqli_connect_errno()) {
$errmsg = "数据库连接失败!\n";
}
else {
// 查询数据库,看用户名及密码是否正确
$sql = "SELECT * FROM t_user WHERE f_username='$username' AND f_password='$pwd'";
$rs = $db->query($sql);
// $rs->num_rows判断上面的执行结果是否含有记录,有记录说明登录成功
if ($rs && $rs->num_rows > 0) {
// 在实际应用中可以使用前面提到的重定向功能转到主页
$errmsg = "登录成功!";
}
else {
$errmsg = "用户名或密码不正确,登录失败!";
}
// 关闭数据库连接
$db->close();
}
}
}
if ($rs && $rs->num_rows > 0) {
// 使用session保存当前用户
session_start();
$_SESSION['uid'] = $username;
// 在实际应用中可以使用前面提到的重定向功能转到主页
$errmsg = "登录成功!";
// 更新用户登录信息
$ip = $_SERVER['REMOTE_ADDR']; // 获取客户端的IP
$sql = "UPDATE t_user SET f_logintimes = f_logintimes + 1,";
$sql .= "f_lasttime=now(), f_loginip='$ip' ";
$sql .= " WHERE f_username='$username'";
$db->query($sql);
}
?>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title>登录</title>
<style type="text/css">
<!--
.abc{
color:red;
}
body {
margin-left: 0px;
margin-top: 0px;
margin-right: 0px;
margin-bottom: 0px;
overflow:hidden;
}
.STYLE3 {font-size: 12px; color: #adc9d9; }
-->
</style>
<script type="text/jscript">
function doCheck(){
if(document.frmLogin.username.value==""){
alert('请输入你的用户名!');
return false;
}
if(document.frmLogin.password.value==""){
alert('请输入你的密码!');
return false;
}
if(document.frmLogin.textfield3.value == ""){
alert('验证码错误,请重新输入!');
return false;
}
}
</script>
</head>
<body>
<table width="100%" height="100%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td colspan="2" align="center" class="abc"><?echo $errmsg;?><?echo $rand;?></td>
</tr>
<tr>
<td height="608" background="images/login_03.gif"><table width="847" border="0" align="center" cellpadding="0" cellspacing="0">
<tr>
<td height="318" background="images/login_04.gif"> </td>
</tr>
<tr>
<td height="84"><table width="100%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td width="381" height="84" background="images/login_06.gif"> </td>
<td width="162" valign="middle" background="images/login_07.gif"><table width="100%" border="0" cellspacing="0" cellpadding="0">
<tr>
<form name="frmLogin" method="post" action="login.php" onSubmit="return doCheck();">
<td height="24" valign="bottom"><div align="right"><label class="STYLE3" for="username">用户</label></div></td>
<td width="10" valign="bottom"> </td>
<td height="24" colspan="2" valign="bottom">
<div >
<input type="text" name="username" id="username" value="<?php echo $username;?>" style="width:100px; height:17px; background-color:#87adbf; border:solid 1px #153966; font-size:12px; color:#283439; ">
</div></td>
</tr>
<tr>
<td height="24" valign="bottom"><div align="right"><span class="STYLE3">密码</span></div></td>
<td width="10" valign="bottom"> </td>
<td height="24" colspan="2" valign="bottom"><input type="password" name="password" id="pwd" style="width:100px; height:17px; background-color:#87adbf; border:solid 1px #153966; font-size:12px; color:#283439; "></td>
</tr>
<tr>
<td height="24" valign="bottom"><div align="right"><span class="STYLE3">验证码</span></div></td>
<td width="10" valign="bottom" ></td>
<td width="52" height="24" valign="bottom"><input type="text" name="textfield3" id="tf3" style="width:50px; height:17px; background-color:#87adbf; border:solid 1px #153966; font-size:12px; color:#283439;" ></td>
<td width="62" valign="bottom"><div align="left"><img src="yanzhengma.php" width="50" height="20"></div></td>
</tr>
<tr><span class="STYLE3" align="center" style:"margin:0px 0px 0px 0px; float:right;" ><nobr>阿萨德飞过后</nobr></span><td height="2" style="width:200px; table-layout:fixed; "></td></tr>
</table></td>
<td width="26"><img src="images/login_08.gif" width="26" height="84"></td>
<td width="67" background="images/login_09.gif"><table width="100%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td height="25"><div align="center"><input type="image" name="" src="images/dl.gif" width="57" height="20" onclick="this.form.submit()"></div></td>
</tr>
<tr>
<td height="25"><div align="center"><input type="image" name="" src="images/cz.gif" width="57" height="20" onclick="this.form.reset();return false"></div></td>
</tr>
</table></td>
</form>
<td width="211" background="images/login_10.gif"> </td>
</tr>
</table></td>
</tr>
<tr>
<td height="206" background="images/login_11.gif" ></td>
</tr>
</table></td>
</tr>
<tr>
<td bgcolor="#152753"> </td>
</tr>
</table>
</body>
</html>
//-----------------------------
<!--<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title>User Login</title>
<style type="text/css">
<!--
.alert {color: red}
.textinput {width:160px}
.btn {width:80px}
table {border: 3px double;background-color:#eeeeee;}
-->
</style>
<script language="javascript">
<!--
function doCheck(){
if(document.frmLogin.username.value==""){
alert('请输入你的用户名!');
return false;
}
if(document.frmLogin.password.value==""){
alert('请输入你的密码!');
return false;
}
}
-->
<!--</script>
</head>
<body>
<form name="frmLogin" method="post" action="login.php" onSubmit="return doCheck();">
<table border="0" cellpadding="8" width="350" align="center">
<tr><td colspan="2" align="center" class="alert"><?php echo $errmsg;?></td></tr>
用户名:
<td><input name="username" type="text" id="username" class="textinput" value="<?echo $username;?>" /></td>
</tr>
<tr><td>密码:</td>
<td><input name="pwd" type="password" id="password" class="textinput" /></td>
</tr>
<tr><td colspan="2" align="center">
<input type="submit" class="btn" value="登录">
<input type="reset" class="btn" value="重置">
</td>
</tr>
</form>
</body>
</html>
-->
[解决办法]
你确定你的确认按钮和你的docheck()函数绑定在了一起吗?
<tr><td colspan="2" align="center">
<input type="submit" class="btn" value="登录">
<input type="reset" class="btn" value="重置">
</td>
</tr>
改成
<input type="submit" class="btn" value="登录" onclick="return docheck();"/>