代码如下:
<html>
<meta type="text/html" charset=utf8>
<form action="form.php" method="POST">
<p>名字: <input type="text" name="name" /></p>
<p>密码: <input type="password" name="password" /></p>
<input type="submit" />
</form>
<?php
error_reporting(0);
$dsn = "mysql:host=localhost;dbname=liuyan";
$db = new PDO($dsn, 'root', 'root');
$name = $_POST['name'];
$password = md5($_POST['password']);
//$date = date("Y-m-d H:i:s");
$sql = "select * from admin where user_name=? and password=?";
$stm = $db->prepare($sql);
$stm->execute(array($name,$password));
$rs=$stm->fetch();
var_dump($rs);
if(empty($rs)){
echo "<script>alert('查询失败');</script>";
} else{
echo "<script>alert('查询成功');</script>";
}
?>
</html>
admin表
现在问题是:fetch取出来用empty判断返回false,为啥会这样?
------解决思路----------------------
说明没有出现错误
因此可以认为你的表中没有符合条件的记录
友情提示:垃圾评论一律封号 加我微信:826096331拉你进VIP群学习群