动态网站流程图:
1. SQL在已有的数据库 test 里创建user表,id,username,password三个字段
2. connect.php写配置文件:
error_reporting(0);
$server="localhost";//主机
$db_username="test";//你的数据库用户名
$db_password="";//你的数据库密码
$con = mysql_connect($server,$db_username,$db_password);//链接数据库
if(!$con){
die("can't connect".mysql_error());//如果链接失败输出错误
}
mysql_select_db('test',$con);//选择数据库(我的是test)
?>
3.register.html注册表单页面:
用户注册页面用户名:
密 码:
4.register.php注册程序:
header("Content-Type: text/html; charset=utf8");
if(!isset($_POST['submit'])){
exit("错误执行");
}
$name=$_POST['name'];
$password=$_POST['password'];
include('connect.php');
$sql="select * from user where username='$name'";//查询是否有相同用户名
$rs= mysql_query($sql,$con);
if(mysql_num_rows($rs)>0)//返回结果集的数目
{
echo "用户名已经存在,请重新注册";
echo "
";
echo "用户注册";
}else
{
$q="insert into user(id,username,password) values (null,'$name','$password')";
$reslut=mysql_query($q,$con);
if (!$reslut){
die('Error: ' . mysql_error());
}else{
echo "注册成功";
echo "
";
echo "立即登入";
}
}
mysql_close($con);
?>
5. login.html登入表单页面:
登陆用户名:
密 码:
6. login.php 登入程序:
header("Content-Type: text/html; charset=utf8");
if(!isset($_POST["submit"])){
exit("错误执行");
}
include('connect.php');
$name = $_POST['name'];
$passowrd = $_POST['password'];
if ($name && $passowrd){
$sql = "select * from user where username = '$name' and password='$passowrd'";
$result = mysql_query($sql);
$rows=mysql_num_rows($result);
if($rows){//0 false 1 true
header("refresh:0;url=welcome.html");
exit;
}else{
echo "用户名或密码错误";
echo "
setTimeout(function(){window.location.href='login.html';},1000);
";
}
}else{
echo "表单填写不完整";
echo "
setTimeout(function(){window.location.href='login.html';},1000);
";
}
mysql_close();
?>
7. welcome.html 登录成功跳转页面
seccess