//进行数据链接,查询; $conn = mysql_connect("localhost:3306","root","123") or die ("无法连接数据库".mysql_error()); mysql_select_db("study",$conn)or die("无法选择数据库".mysql_error());
$sql1 = "select * from userinfo where username = '$name' and password = '$pword'"; $result = mysql_query($sql1,$conn);
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>无标题文档</title>
<style type="text/css">
<!--
.STYLE1 {font-size: 16px}
.STYLE2 {font-size: 18px; }
-->
</style>
</head>
<script language="javascript">
function check(){
if (form1.username.value == ""){
alert('用户名不能为空');
form1.username.focus();
return false;
}
else if(form1.password.value == ""){
alert('密码不能为空!');
form1.password.focus();
return false;
} }
</script>
<body>
<form id="form1" name="form1" method="post" action="ChkLogin.php" onsubmit="return check()">
<p> </p>
<p align="center" class="STYLE2">用户登录</p>
<p align="center">用户名:<input type="text" name="username" value="" /></p>
<p align="center"> 密 码:
<input type="text" name="password" value="" /></p>
<p align="center">
<input type="submit" name="button1" value="登录" />
<input type="reset" name="reset1" value="取消" />
</p>
</form></body>
</html>
自己在连个数据库就行了,不过我的没有用MD5加密。
<?php
//获得提交的用户名和密码;
$name = $_POST['username'];
$pword = $_POST['password'];
//进行数据链接,查询;
$conn = mysql_connect("localhost:3306","root","123") or die ("无法连接数据库".mysql_error());
mysql_select_db("study",$conn)or die("无法选择数据库".mysql_error());
$sql1 = "select * from userinfo where username = '$name' and password = '$pword'";
$result = mysql_query($sql1,$conn);
$num = mysql_num_rows($result);
if ($num > 0){
header("Location:bbspage.php");
}
else{
echo "用户名或者密码出错!";
}
mysql_close();
?>写的简单,别见笑
if(isset($_POST['submit'])){
session_start();
mysql_connect("localhost","root","");
mysql_select_db("php");
mysql_query("set names utf8");
$uname = $_POST[uname];
$pwd = $_POST[pwd];
$uname = trim($uname);
$sql = "select * from user where username='$uname' and password='$pwd'";
$result = mysql_query($sql); $row = mysql_fetch_array($result);
if ($row) { echo '登陆成功';
}
else
echo "用户名或密码错误";
}?>
<html>
<form method="POST">
用户名:<input type="text" name="uname"><br>
密 码:<input type="password" name="pwd"><br>
<input type="submit" value="登陆" name="submit"></form>
</html>