登录的代码是这样
<?php
/** file:login.inc.php 登录系统的主控制文件和主入口文件*/
/*声明一个删除Cookie的函数,调用时消除在客户端设置的所以Cookie*/
function clearCookies(){
//只指定Cookie识别名称一个参数,即删除客户端中这个指定名称的Cookie资料
//生存空间默认为空,则生存期限与浏览器一样,浏览器关闭时Cookie就会被删除
setcookie('name');
setcookie('isLogin');
}
include "conn/conn.php";
@$username = htmlspecialchars($_POST['name']);
@$pwd = $_POST['pwd'];
$pwd = md5($pwd);
/*如果用户的操作是提交表单,则条件成立*/
if(isset($_POST['submit'])){
clearCookies();
$sql = "SELECT * FROM tb_grnews WHERE name = '$name' and pwd='$pwd'";
$res = mysql_query($sql,$link);
/*mysql_num_rows只能用于select语句*/
$rows=mysql_num_rows($res);
if($rows>0){
/*向Cookie中设置标识符为username,值是表单中提交的,期限为一周*/
setcookie('username',$username,time()+60*60*24*7);
/*向Cookie中设置标识符为isLogin,用来在其它页面检查用户是否登录*/
setcookie('isLogin','1',time()+60*60*24*7);
/*如果Cookie设置成功则转向网站首页*/
header("Location:index.php");//跳转页面,注意路径
}else{
echo '<font color="red">用户名或密码错误!</font>';
}
}else if(@$_GET["action"]=="logout"){
//退出时消除在客户端设置的所有Cookie
clearCookies();
}
?>
<html>
<head>
<title>登录系统</title>
<meta charset="utf-8" />
<link rel="stylesheet" href="login.css" />
</head>
<body>
<div class="content">
<!-- 登录面板 -->
<div class="panel">
<form action="login.inc.php" method="post">
<div class="group">
<label for="username">用户名:</label>
<input id="name" type="text" name="name" placeholder="请输入账号" />
</div>
<div class="group">
<label for="pass">密码:</label>
<input id="pwd" type="password" name="pwd" placeholder="请输入密码" />
</div>
<div class="login">
<button type="submit" name="submit">登录</button>
</div>
<div class="register">
<input name="" type="reset" value="重置">
</div>
</form>
</div>
</body>
</html>
数据库连接的代码是这样
<?php
$link=mysqli_connect("localhost","root","111","1024") or die("数据库连接失败".mysql_error());
mysqli_query($link,"set names gb2312");
?>
明明输对账号密码却始终显示错误