php登录注册

在度娘帮助下终于完成php登录注册,在这个过程中学习到了一些php 中的MySQL()函数。

登录页面html:

<!DOCTYPE html>
<head>
<meta charset="UTF-8">
<title>登录</title>
<style>
html{font-size:12px;}
fieldset{300px; margin: 0 auto;}
legend{font-weight:bold; font-size:14px;}
label{float:left; 70px; margin-left:10px;}
.left{margin-left:80px;}
.input{150px;}
span{color: #666666;}
</style>
</head>
<body>
<div>
<fieldset>
<legend>用户登录</legend>
<form name="LoginForm" method="post" action="login.php" onSubmit="return InputCheck(this)">
<p>
<label for="username" class="label">姓名:</label>
<input id="username" name="username" type="text" class="input" />
</p>
<p>
<label for="password" class="label">密 码:</label>
<input id="password" name="password" type="password" class="input" />
</p>
<p>
<input type="submit" name="submit" value=" 确 定 " class="left" />
</p>
<p>
<a href = "register.html">立即注册</a>
</p>
</form>
</fieldset>
</div>
<script language=JavaScript>
function InputCheck(LoginForm)
{
if (LoginForm.username.value == "")
{
alert("请输入用户名!");
LoginForm.username.focus();
return (false);
}
if (LoginForm.password.value == "")
{
alert("请输入密码!");
LoginForm.password.focus();
return (false);
}
}
</script>
</body>
</html>

登录页面php:

<!DOCTYPE html>
<head>
<meta charset="UTF-8">
<title>登录</title>
</head>
<body>

<?php
//包含数据库连接文件
include('conn.php');
session_start();

//登录
if(!isset($_POST['submit'])){
exit('非法访问!');
}
$username = htmlspecialchars($_POST['username']);
$password = $_POST['password'];

//包含数据库连接文件
include('conn.php');
//检测用户名及密码是否正确;
$check_query = mysql_query("select username,password from user where username='$username' limit 1");
$num = mysql_num_rows($check_query);
if($num){
$row = mysql_fetch_array($check_query);
if($username==$row[0] && $password==$row[1]){
echo $username,' 欢迎你!进入 <a href="money.php">用户中心</a><br />';
exit;
}else{
exit('登录失败!账号或密码错误,点击此处 <a href="javascript:history.back(-1);">返回</a> 重试');
}
}
?>
</body>
</html>

 注册页面:

<!DOCTYPE html>
<head>
<meta charset="UTF-8">
<title>注册</title>
<style>
html{font-size:12px;}
fieldset{300px; margin: 0 auto;}
legend{font-weight:bold; font-size:14px;}
label{float:left; 70px; margin-left:10px;}
.left{margin-left:80px;}
.input{150px;}
span{color: #666666;}
</style>
</head>
<body>
<fieldset>
<legend>用户注册(必须填写完整)</legend>
<form name="LoginForm" method="post" action="register.php" onSubmit="return InputCheck(this)">
<p>
<label for="account" class="label">姓名:</label>
<input id="account" name="username" type="text" class="input" />
</p>
<p>
<label for="number" class="label">手机号:</label>
<input id="number" name="phone" type="text" class="input" />
</p>
<p>
<label for="password" class="label">密码:</label>
<input id="password" name="password" type="password" class="input" />
<p style="margin-left: 100px;">密码长度6-18位</p>
</p>
<p>
<label for="repassword" class="label">确认密码:</label>
<input id="repassword" name="repassword" type="password" class="input" />
</p>
<p>
<input type="submit" name="submit" value=" 确 定 " class="left" />
</p>
</form>
</fieldset>


</body>
</html>

注册页面php:

<!DOCTYPE html>
<head>
<meta charset="UTF-8">
<title>注册</title>
</head>
<body>
<?php
//包含数据库连接文件
include('conn.php');
if(!isset($_POST['submit'])){
exit('非法访问!');
}
$username = $_POST['username'];
$password = $_POST['password'];
$repassword = $_POST['repassword'];
$phone = $_POST['phone'];

//注册信息判断
if(strlen($password) < 6){
exit('错误:密码长度不符合规定。<a href="javascript:history.back(-1);">返回</a>');
}
if($username == "" || $password == "" || $repassword == "" || $phone ==""){
echo "<script>alert('请确认信息完整性!'); history.go(-1);</script>";
}else{
if($password == $repassword){
//检测用户名是否已经存在
$check_query = mysql_query("select id from user where username='$username' limit 1");
if(mysql_fetch_array($check_query)){
//echo "mysql_fetch_array($check_query)";
echo '错误:姓名 ',$username,' 已存在。<a href="javascript:history.back(-1);">返回</a>/<a href="login.html">登录</a>';
exit;
}
//写入数据
$password = $password;
$regdate = time();
$sql = "INSERT INTO user(username,phone,password)VALUES('$username','$phone','$password')";
if(mysql_query($sql,$conn)){
exit('用户注册成功!点击此处 <a href="login.html">登录</a>');
} else {
echo '抱歉!添加数据失败:',mysql_error(),'<br />';
echo '点击此处 <a href="javascript:history.back(-1);">返回</a> 重试';
}
}else{
echo "<script>alert('密码不一致!'); history.go(-1);</script>";
}

}


?>
</body>
</html>

money.php

<!DOCTYPE html>
<head>
<meta charset="UTF-8">
<title>账单</title>
<style>
table{500px;marigin: 0 auto}
table tr{height: 30px;}
table tr td{text-align: center;}
table tr:nth-child(2n+1){background: #F4F4F4; }
</style>
</head>
<body>
<?php
//包含数据库连接文件
include('conn.php');
?>
<p class="">总账:
<?php
$p = "select*from total";
$money = mysql_query($p);
$q = "select*from Bill";//设置查询指令
$result = mysql_query($q);//执行查询
while($s = mysql_fetch_assoc($money)){
while($row = mysql_fetch_assoc($result)){
$s["qian"] = $s["qian"] + $row["in_outcome"];
}
echo "<span>".$s["qian"]."</span>";
}
?>
</p>
<table>
<tr>
<td>编号</td>
<td>进出账目</td>
<td>来源/接收</td>
</tr>
<?php
$q = "select*from Bill";//设置查询指令
$result = mysql_query($q);//执行查询
while($row = mysql_fetch_assoc($result))//将result结果集中查询结果
{
//echo "$row[in_outcome]";
echo"<tr><td>".$row["id"]."</td><td>".$row["in_outcome"]."</td><td>".$row["username"]."</td></tr>";
};

?>

</table>
</body>
</html>

原文地址:https://www.cnblogs.com/namehou/p/6971736.html