sql在最下面!!!
php.php
<!DOCTYPE html> <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
<!DOCTYPE html> <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> <?php //用户输入的(表单传过来的) $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管理系统成功啦');location.href='login.php';</script>";
登录:login.php
<!DOCTYPE html> <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> <?php session_start(); //用户输入的(表单传过来的) $username=$_POST['username']; $password=$_POST['password']; if(!$username||!$password) { $_SESSION['login']=0; exit(); } else { $_SESSION['login']=1; //========================= $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
<?php session_start(); if($_SESSION['login']!=1) { echo "<script>alert('抱歉,用户还没登录');window.location.href='login.php';</script>"; } ?> <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>Document</title> </head> <body> <a href="ft.php">点击发帖</a> </body> </html>
发帖页:ft.php
<!doctype html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0"> <meta http-equiv="X-UA-Compatible" content="ie=edge"> <title>Document</title> </head> <body> <form action="ft.php" method="POST" enctype="multipart/form-data"> <!--<input type="hidden" name="MAX_FILE_SIZE" value="30000" />--> Send this file: <input name="file" type="file" /> <textarea name="content" id="" cols="300" rows="100"></textarea> <input type="submit" value="提交" /> </form> </script> </body> </html> <?php $link=mysqli_connect('localhost','root','','a'); mysqli_set_charset($link,'utf8'); $content=$_POST['content']; echo move_uploaded_file($_FILES['file']['tmp_name'],'../upload/'.basename($_FILES['file']['name'])); $file='../upload/'.basename($_FILES['file']['name']); $sql = "INSERT INTO ft(content,file) VALUES ('{$content}','{$file}')"; mysqli_query($link,$sql); ?> <a href="list.php">回到列表页</a>
列表页:list.php
<?php $link=mysqli_connect('localhost','root','','a'); //然后是指定php链接数据库的字符集 mysqli_set_charset($link,'utf8'); $sql="select * from ft"; //模糊查询出像数据库中的title或者content里面的值或者说像数据库中的title或者content里面的某一段值相对应的就行了,就可以输出啦 $result=mysqli_query($link,$sql);//运行sql ?> <!--显示的效果--> <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>Document</title> </head> <body> <?php while ($row=mysqli_fetch_array($result)) {//把对象编程数组输出,不然会报错哦 # code... echo "<div>$row[content]</div>"; echo "<a href='detail.php?id=$row[id]'><img src=$row[file] /></a>"; } ?> </body> </html>
详情页:detail.php
<?php $id=$_GET['id']; $link=mysqli_connect('localhost','root','','a'); //然后是指定php链接数据库的字符集 mysqli_set_charset($link,'utf8'); $sql="select * from ft where id=$id"; //模糊查询出像数据库中的title或者content里面的值或者说像数据库中的title或者content里面的某一段值相对应的就行了,就可以输出啦 $result=mysqli_query($link,$sql);//运行sql while ($row=mysqli_fetch_array($result)) {//把对象编程数组输出,不然会报错哦 # code... echo "<div>$row[content]</div>"; } ?>
-- phpMyAdmin SQL Dump -- version 4.5.1 -- http://www.phpmyadmin.net -- -- Host: 127.0.0.1 -- Generation Time: 2022-04-04 16:29:26 -- 服务器版本: 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` -- -- -------------------------------------------------------- -- -- 表的结构 `ft` -- CREATE TABLE `ft` ( `id` int(30) NOT NULL, `content` text COLLATE utf8_vietnamese_ci NOT NULL, `file` varchar(255) COLLATE utf8_vietnamese_ci NOT NULL ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_vietnamese_ci; -- -- 转存表中的数据 `ft` -- INSERT INTO `ft` (`id`, `content`, `file`) VALUES (12, 'aaa', '../upload/1.jpg'), (13, '', '../upload/'), (14, '666', '../upload/8c97b378cb62cb233382d763cf6c90ef.jpeg'); -- -------------------------------------------------------- -- -- 表的结构 `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 (50, 'cyg', '123456'); -- -- Indexes for dumped tables -- -- -- Indexes for table `ft` -- ALTER TABLE `ft` ADD PRIMARY KEY (`id`); -- -- Indexes for table `login` -- ALTER TABLE `login` ADD PRIMARY KEY (`id`); -- -- 在导出的表使用AUTO_INCREMENT -- -- -- 使用表AUTO_INCREMENT `ft` -- ALTER TABLE `ft` MODIFY `id` int(30) NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=15; -- -- 使用表AUTO_INCREMENT `login` -- ALTER TABLE `login` MODIFY `id` int(11) NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=51; /*!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 */;