完整教程PHP留言板
登陆界面
一个初学者的留言板(登录和注册)_php留言板登录注册-CSDN博客
留言板功能介绍
百度网盘 请输入提取码 进入百度网盘后,输入提取码:knxt,即可下载项目素材和游客访问页面的模板文件。
<?php session_start(); ?>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" /><title>登陆</title>
</head>
<body>
<center>
<h1>登陆</h1>
<?php
include "conn.php";
if (isset($_POST["submit"])){if (empty($_POST["user"]) or empty($_POST["password"])) {echo "<font color='red'> 用户名或者密码不能为空,请重新输入!</font>";}else{$user = $_POST["user"];$password = $_POST["password"];$sql = "select * from user where username = '$user' and password = '$password'";//echo $sql;$result = mysqli_query($conn,$sql);if (mysqli_num_rows($result) > 0) {//echo "<font color='green'>登陆成功!</font>";$persion = mysqli_fetch_array($result);//取结果集result的值赋给persion$_SESSION["username"] = $persion["username"];//session取值方便后面的使用//echo $_SESSION["username"];$_SESSION["uid"] = $persion["uid"];//echo $_SESSION["uid"];echo "<script>alert('登陆成功')</script>";}else{echo "<font color='red'>用户名或者密码不存在!</font>";}}}
?><form action="<?php echo $_SERVER["PHP_SELF"]; ?>" method="post" > <table border="0" >
<tr >
<td >用户名</td>
<td ><input type="text" name="user" ></td>
</tr>
<br />
<tr>
<td>密码</td>
<td><input type="password" name="password"></td>
</tr>
<br />
<tr> <!--colspan 属性规定单元格可横跨的列数。-->
<td colspan="2" align="center"><input type="submit" value="登陆" name="submit">
<input type="submit" name="zhuce" value="注册" onClick="window.open('zhuce.php')">
<!--<input type="button" value="注册" οnclick="document.location.href='http://127.0.0.1/5.php'" >--></td></tr>
</table>
</form></center>
</body>
</html>