php留言板
利用php制作一个简单的留言板,可实现用户注册和登录,发表留言,修改留言,删除留言,查看留言
需要用到两张表,一张用来存储账号信息,另一张用来存储留言信息
user表
liuyan表
接下来是php代码
login_0.php
<form method ="POST" action = "login.php" name="frmLogin">
<tr align="center" style="font-size:25px;">
<td colspan="2" style="font-size:35px;">用户登陆</td></br>
</tr>
<tr>
<td align="center" style="font-size:25px;">用户名</td>
<td><input type="text" maxlength="16" name="username" placeholder="请输入账号" style="width:180px;font-size:20px;border-radius: 8px; "></td></br>
</tr>
<tr>
<td align="center" style="font-size:25px;">密 码</td>
<td><input name="password" type="password" maxlength="16" placeholder="请输入密码" style="width:180px;font-size:20px;border-radius: 8px; "></td></br>
</tr>
<tr align="center">
<td colspan="2">
<input type="submit" name="denglu" value="登陆" class="btn">
<input type="reset" name="rs" value="重置" class="btn">
<input type="button" name="zu" value="注册" onclick="window.location.href='register_0.php'" class="btn"/>
</td>
</tr>
</form>
<script type="text/javascript">
// 验证输入不为空的脚本代码
function checkForm(form) {
if(form.username.value == "") {
alert("用户名不能为空!");
form.username.focus();
return false;
}
if(form.password.value == "") {
alert("密码不能为空!");
form.password.focus();
return false;
}
return true;
}
</script>
</body>
</html>
login.php
<?php
session_start();
header("content-type:text/html;charset=utf-8");
//连接数据库
$conn = mysqli_connect("localhost","root","123456","liuyan");
if (!$conn) {
die("连接失败: " . mysqli_connect_error());
}
//接收$_POST用户名和密码
$username = $_POST[&