**
登录页面login.html 跳转至login.php
**
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>登录</title>
<script src="./jquery-3.3.1.min.js"></script>
</head>
<body>
<form action="login.php" method="post">
<input type="text" name="user_name" class="name"><span class="jname"></span>
<input type="password" name="user_pwd" class="pwd"><span class="jpwd"></span>
<input type="submit" value="登录">
</form>
</body>
</html>
<script>
$(document).on('click','.name',function(){
$('.jname').html('请输入用户名');
})
$(document).on('blur','.name',function(){
// $('.jname').html('用户名不能为空');
user_name = $('.name').val();
if(!/^[\u4e00-\u9fa5]{3,16}$/.test(user_name))
{
$('.jname').html('请规范名称长度');
}else{
$('.jname').html('ok');
}
})
$(document).on('click','.pwd',function(){
$('.jpwd').html('请输入密码');
})
$(document).on('blur','.pwd',function(){
user_pwd = $('.pwd').val();
if(!/^[0-9]{6,18}$/.test(user_pwd))
{
$('.jpwd').html('密码长度不正确');
}else{
$('.jpwd').html('ok');
}
})
</script>
**
login.php 跳转至add.html添加页面
**
<?php
header('content-type:text/html;charset=utf8');
try
{
$dbh = new PDO('mysql:host=localhost;dbname=xuebaba', 'root', 'root');
}
catch (PDOException $e)
{
print "Error!: " . $e->getMessage() . "<br/>";
die();
}
$dbh->exec("set names utf8");
$user_name=$_POST['user_name'];
$user_pwd = $_POST['user_pwd'];
$sql = "select * from user where user_name = '$user_name' and user_pwd = '$user_pwd'";//接收用户名 和
$res=$dbh->query($sql);
if($res)
{
echo "<script>alert('登录成功');location.href='add.html';</script>";
}
else
{
echo "登录失败";
}
**
add.html添加页面 跳转至add.php
**
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>添加</title>
</head>
<body>
<form action="add.php" method="post">
用户名:<input type="text" name="user_name">
密码:<input type="text" name="user_pwd">
<input type="submit" value="添加">
</form>
</body>
</html>
**
**
add.php页面 (跳转至show页面)
<?php
header('content-type:text/html;charset=utf8');
ob_start();
try
{
$dbh = new PDO('mysql:host=localhost;dbname=xuebaba', 'root', 'root');
}
catch (PDOException $e)
{
print "Error!: " . $e->getMessage() . "<br/>";
die();
}
$user_name=$_POST['user_name'];
$user_pwd=$_POST['user_pwd'];
$dbh->exec("set names utf8");
$sql="insert into user value(null,'$user_name','$user_pwd')";
$res=$dbh->exec($sql);
if($res)
{
echo "<script>alert('提交成功');location.href='show.php';</script>";
}
else
{
echo "提交失败";
}
?>
**
**
**
show展示页面
**
<?php
header('content-type:text/html;charset=utf8');
if (is_file('show.html') && time()-filemtime('show.html')<10) {
include_once('show.html');
die();
}else{
ob_start();
try
{
$dbh = new PDO('mysql:host=localhost;dbname=xuebaba', 'root', 'root');
}
catch (PDOException $e)
{
print "Error!: " . $e->getMessage() . "<br/>";
die();
}
// $user_name=$_GET['user_name'];
// $user_pwd=$_GET['user_pwd'];
$dbh->exec("set names utf8");
$sql="select * from user ";
$res=$dbh->query($sql);
$data=$res->fetchAll(2);
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>show</title>
</head>
<body>
<center>
<table>
<tr>
<td>id</td>
<td>用户名</td>
<td>密码</td>
<td>操作</td>
</tr>
<?php foreach ($data as $key => $value){ ?>
<tr>
<td><?php echo $value['user_id']; ?></td>
<td><?php echo $value['user_name']; ?></td>
<td><?php echo $value['user_pwd']; ?></td>
<td><a href="del.php?user_id=<?php echo $value['user_id']?>">删除</a>|<a href="upd.php?user_id=<?php echo $value['user_id']?>">修改</a></td>
</tr>
<?php } ?>
</table>
</center>
</body>
</html>
<?php
file_put_contents('show.html', ob_get_contents());
}
?>
删除页面del
<?php
header('content-type:text/html;charset=utf8');
ob_start();
try
{
$dbh = new PDO('mysql:host=localhost;dbname=xuebaba', 'root', 'root');
}
catch (PDOException $e)
{
print "Error!: " . $e->getMessage() . "<br/>";
die();
}
$user_id=$_GET['user_id'];
$dbh->exec("set names utf8");
$sql="delete from user where user_id=$user_id";
$res=$dbh->exec($sql);
if($res)
{
echo "<script>alert('删除成功');location.href='show.php';</script>";
}
else
{
echo "<script>alert('删除失败');location.href='show.php';</script>";
}
?>
**
修改页面upd
**
<?php
try
{
$dbh = new PDO('mysql:host=localhost;dbname=xuebaba', 'root', 'root');
}
catch (PDOException $e)
{
print "Error!: " . $e->getMessage() . "<br/>";
die();
}
$user_id=$_GET['user_id'];
$dbh->exec("set names utf8");
$sql="select * from user where user_id='$user_id'";
$res=$dbh->query($sql);
$data=$res->fetch(2);
// print_r($data);
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Document</title>
</head>
<body>
<form action="upddo.php">
<input type="hidden" value="<?php echo $data['user_id']?>" name="user_id" >
用户名:<input type="text" name="user_name" value="<?php echo $data['user_name']?>">
密码:<input type="text" name="user_pwd" value="<?php echo $data['user_pwd']?>">
<input type="submit" value="提交">
</form>
</body>
</html>
**
upddo 修改
**
<?php
header('content-type:text/html;charset=utf8');
try
{
$dbh = new PDO('mysql:host=localhost;dbname=xuebaba', 'root', 'root');
}
catch (PDOException $e)
{
print "Error!: " . $e->getMessage() . "<br/>";
die();
}
$user_id=$_GET['user_id'];
$user_name=$_GET['user_name'];
$user_pwd = $_GET['user_pwd'];
$dbh->exec("set names utf8");
$sql="update user set user_name='$user_name', user_pwd = '$user_pwd' where user_id=$user_id";
$res=$dbh->exec($sql);
if ($res) {
echo "<script>alert('修改成功');location.href='show.php'</script>";
}else{
echo "<script>alert('修改成功');location.href='show.php'</script>";
}
?>