mysql_select_db("homework", $conn)
mysql_query("SET NAMES 'UTF8'",$conn)
$username=$_POST['user_email']
$password=$_POST['password']
$sql = "select * from user where username='$username' and password='$password'"
$Result = mysql_query($sql, $conn)
$onerow = mysql_fetch_array($Result)
if ( $onerow )
echo "正确"
else
echo "错误"
如果不考虑sql注入,不过率用户输入信息的话,最简单的代码如下:<?php
if($_SERVER['REQUEST_METHOD'] == 'POST'){
$db = mysql_connect("localhost","root","123") or die("fail")
echo "connect ok!<br>"
mysql_select_db('ck')
$_POST['pwd'] = md5($_POST['pwd'])//如果数据库里存的不是md5码,这句就不用了
$sql = "select * from adminuser where username='{$_POST['name']}' and password='{$_POST['pwd']}'"
$result = mysql_query($sql)
if(mysql_num_rows($result) != 0){
echo "找到了!"
}
else{
echo "没这个人!"
}
exit()
}
?>
<html>
<head>
<meta http-equiv="Content-Type" content="text/htmlcharset=gb2312" />
<title>用户信息</title>
</head>
<form name="fm" action="" method="post">
<input type="text" name="name" value="" />
<input type="password" name="pwd" value="" />
<input type="submit" value="提交" />
</form>
</html>
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)