源代码在贵哥的编程之路资源里面
-- phpMyAdmin SQL Dump
-- version 4.5.1
-- http://www.phpmyadmin.net
--
-- Host: 127.0.0.1
-- Generation Time: 2022-03-18 09:40:15
-- 服务器版本: 10.1.13-MariaDB
-- PHP Version: 5.6.21
SET SQL_MODE = "NO_AUTO_VALUE_ON_ZERO";
SET time_zone = "+00:00";
/*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */;
/*!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS */;
/*!40101 SET @OLD_COLLATION_CONNECTION=@@COLLATION_CONNECTION */;
/*!40101 SET NAMES utf8mb4 */;
--
-- Database: `a`
--
-- --------------------------------------------------------
--
-- 表的结构 `login`
--
CREATE TABLE `login` (
`id` int(11) NOT NULL,
`username` varchar(100) COLLATE utf8_vietnamese_ci NOT NULL COMMENT '用户名',
`password` varchar(100) COLLATE utf8_vietnamese_ci NOT NULL COMMENT '密码'
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_vietnamese_ci;
--
-- 转存表中的数据 `login`
--
INSERT INTO `login` (`id`, `username`, `password`) VALUES
(48, 'cyg&liwen', 'cyg&liwen'),
(49, 'kkkk', 'kkkk');
-- --------------------------------------------------------
--
-- 表的结构 `search`
--
CREATE TABLE `search` (
`id` int(11) NOT NULL DEFAULT '0',
`content` text COLLATE utf8_vietnamese_ci NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_vietnamese_ci;
--
-- 转存表中的数据 `search`
--
INSERT INTO `search` (`id`, `content`) VALUES
(2, 'liwen'),
(555, 'liwen&cyg'),
(0, '6149viv'),
(0, '494949494\r\n'),
(0, '4+46\r\n');
--
-- Indexes for dumped tables
--
--
-- Indexes for table `login`
--
ALTER TABLE `login`
ADD PRIMARY KEY (`id`);
--
-- 在导出的表使用AUTO_INCREMENT
--
--
-- 使用表AUTO_INCREMENT `login`
--
ALTER TABLE `login`
MODIFY `id` int(11) NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=50;
/*!40101 SET CHARACTER_SET_CLIENT=@OLD_CHARACTER_SET_CLIENT */;
/*!40101 SET CHARACTER_SET_RESULTS=@OLD_CHARACTER_SET_RESULTS */;
/*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */;
php.php看你想注册还是登录
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Document</title>
</head>
<body>
<a href="registered.php">注册</a>
<a href="login.php">登陆</a>
</body>
</html>
registered.php注册
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Document</title>
</head>
<body>
<form action="registered.php" method="POST">
<input type="text" name="username">
<input type="password" name="password">
<input type="submit" value="提交">
</form>
</body>
</html>
//用户输入的(表单传过来的)
$username=$_POST['username'];
$password=$_POST['password'];
if(!$username||!$password)
{
exit();
}
$link=mysqli_connect('localhost','root','','a');
//然后是指定php链接数据库的字符集
mysqli_set_charset($link,'utf8');
$sql = "INSERT INTO login(username,password)
VALUES ('{$username}','{$password}')";
$query=mysqli_query($link,$sql);
echo "<script>alert('恭喜你,注册cyg管理系统成功啦')</script>";
login登录
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Document</title>
</head>
<body>
<form action="login.php" method="POST">
<input type="text" name="username">
<input type="password" name="password">
<input type="submit" value="提交">
</form>
</body>
</html>
//用户输入的(表单传过来的)
$username=$_POST['username'];
$password=$_POST['password'];
if(!$username||!$password)
{
exit();
}
//=========================
$link=mysqli_connect('localhost','root','','a');
//然后是指定php链接数据库的字符集
mysqli_set_charset($link,'utf8');
//查询然后判断数据库中的用户名username+密码password是不是与表单传过来的$username+$password相匹配.
$sql="select * from login where username='{$username}' and password='{$password}'";
$query=mysqli_query($link,$sql);//运行sql
$result=mysqli_fetch_array($query);//把对象变成数组,不然直接输出会报错
if($result)
{
echo "<script>alert('登录成功');window.location.href='index.php';</script>";
}
else
{
echo "<script>alert('抱歉,用户还没注册过')</script>";
}
增删改查的列表index.php
$link=mysqli_connect('localhost','root','','a');
//然后是指定php链接数据库的字符集
mysqli_set_charset($link,'utf8');
$sql="select * from search";
//模糊查询出像数据库中的title或者content里面的值或者说像数据库中的title或者content里面的某一段值相对应的就行了,就可以输出啦
$result=mysqli_query($link,$sql);//运行sql
<!--显示的效果-->
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Document</title>
</head>
<body>
<button><a href="lyb.php">留言板功能</a></button>
<table border="1" cellpadding="5">
<tr>
<td>id</td>
<td>标题</td>
<td>内容</td>
while ($row=mysqli_fetch_array($result)) {//把对象编程数组输出,不然会报错哦
# code...
<tr>
<td>=$row['id'];</td>
<td>=$row['content'];</td>
<td><a href="update.php?id= echo $row['id']; ">更新</a></td>
<td><a href="delete.php?id= echo $row['id']; ">删除</a></td>
<td><a href="create.php">创建</a></td>
</tr>
}
</tr>
</table>
</body>
</html>
create.php
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Document</title>
</head>
<body>
<form action="create.php" method="POST">
<input type="text" name="content">
<input type="submit" value="提交">
</form>
</body>
</html>
if(!$_POST['content'])
{
exit();
}
$content=$_POST['content'];
$link=mysqli_connect('localhost','root','','a');
//然后是指定php链接数据库的字符集
mysqli_set_charset($link,'utf8');
$sql = "INSERT INTO search(content)
VALUES ('{$content}')";
$result=mysqli_query($link,$sql);
echo "<script>alert('创建成功');</script>";
delete.php
$link=mysqli_connect('localhost','root','','a');
//然后是指定php链接数据库的字符集
mysqli_set_charset($link,'utf8');
//$sql = "DELETE FROM `search` WHERE `id` = '$_POST[id]'";
//模糊查询出像数据库中的title或者content里面的值或者说像数据库中的title或者content里面的某一段值相对应的就行了,就可以输出啦
$result=mysqli_query($link,"DELETE FROM search WHERE id ='$_GET[id]'");//运行sql
$sql="select * from search";
//模糊查询出像数据库中的title或者content里面的值或者说像数据库中的title或者content里面的某一段值相对应的就行了,就可以输出啦
$result=mysqli_query($link,$sql);//运行sql
<!--显示的效果-->
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Document</title>
</head>
<body>
<table border="1" cellpadding="5">
<tr>
<td>id</td>
<td>标题</td>
<td>内容</td>
while ($row=mysqli_fetch_array($result)) {//把对象编程数组输出,不然会报错哦
# code...
<tr>
<td>=$row['id'];</td>
<td>=$row['content'];</td>
<td><a href="update.php?id== $row['id']; ">更新</a></td>
<td><a href="delete.php?id== $row['id']; ">删除</a></td>
<td><a href="create.php">创建</a></td>
</tr>
}
</tr>
</table>
</body>
</html>
update.php
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Document</title>
</head>
<body>
<form action="update.php" method="GET">
<input type="hidden" name="id" value=" echo $_GET['id']">
<input type="text" name="content">
<input type="submit" value="搜索">
</form>
</body>
</html>
$link=mysqli_connect('localhost','root','','a');
//然后是指定php链接数据库的字符集
mysqli_set_charset($link,'utf8');
//$sql = "DELETE FROM `search` WHERE `id` = '$_POST[id]'";
//模糊查询出像数据库中的title或者content里面的值或者说像数据库中的title或者content里面的某一段值相对应的就行了,就可以输出啦
$result=mysqli_query($link,"UPDATE search set content='$_GET[content]' WHERE id ='$_GET[id]'");//运行sql
$sql="select * from search";
//模糊查询出像数据库中的title或者content里面的值或者说像数据库中的title或者content里面的某一段值相对应的就行了,就可以输出啦
$result=mysqli_query($link,$sql);//运行sql
<!--显示的效果-->
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Document</title>
</head>
<body>
<table border="1" cellpadding="5">
<tr>
<td>id</td>
<td>标题</td>
<td>内容</td>
while ($row=mysqli_fetch_array($result)) {//把对象编程数组输出,不然会报错哦
# code...
<tr>
<td>=$row['id'];</td>
<td>=$row['content'];</td>
<td><a href="update.php?id== $row['id']; ">更新</a></td>
<td><a href="delete.php?id== $row['id']; ">删除</a></td>
<td><a href="create.php">创建</a></td>
</tr>
}
</tr>
</table>
</body>
</html>
留言板:
header("Content-type:text/html;charset=utf-8");
<style>
body{
background:#ccc;
}
.blue
{
background:rgba(255,123,169);
width: 260px;
height:auto;
}
</style>
论坛留言<br>
<form name="myForm" action="lyb.php" method="post" onsubmit="return check()">
<textarea name="text"></textarea>
<br><br>
<input type="submit" value="发布回帖">
</form>
<script>
function check(){
if(document.myForm.text.value==""){
alert("不能为空");
return false;
}
return true;
}
</script>
if(!empty($_POST['text'])){
$str = $_POST['text'];
$link=mysqli_connect('localhost','root','','a');
//然后是指定php链接数据库的字符集
mysqli_set_charset($link,'utf8');
$sql = "INSERT INTO search(content)
VALUES ('{$str}')";//把发言的数据插入数据库中,然后后面点击按钮从数据库中读取出来
mysqli_query($link,$sql);//运行sql
$sql="select * from search";
$result=mysqli_query($link,$sql);//运行sql
while ($row=mysqli_fetch_array($result)) {
# code...
echo "<div class='blue'>{$row['content']}</div><br>";
}
}