Skip to content
This repository has been archived by the owner on Oct 2, 2022. It is now read-only.

修改了乱码和数据库配置文件的位置 #1

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 37 additions & 0 deletions .project
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>lovewall-master</name>
<comment></comment>
<projects>
</projects>
<buildSpec>
<buildCommand>
<name>com.aptana.ide.core.unifiedBuilder</name>
<arguments>
</arguments>
</buildCommand>
</buildSpec>
<natures>
<nature>com.aptana.projects.webnature</nature>
</natures>
<filteredResources>
<filter>
<id>1508224238158</id>
<name></name>
<type>26</type>
<matcher>
<id>org.eclipse.ui.ide.multiFilter</id>
<arguments>1.0-name-matches-false-false-node_modules</arguments>
</matcher>
</filter>
<filter>
<id>1508225223391</id>
<name></name>
<type>26</type>
<matcher>
<id>org.eclipse.ui.ide.multiFilter</id>
<arguments>1.0-name-matches-false-false-node_modules</arguments>
</matcher>
</filter>
</filteredResources>
</projectDescription>
7 changes: 5 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@
先将根目录内的 options.sql 和 contents.sql 导入数据库

#### 连接数据库
在 /require/function.php 的第三行更改为自己的数据库信息
在 /require/conf.php 更改为自己的数据库信息

$mysql=array ('mysql'=>'数据库地址(默认localhost)','name'=>'数据库名称','password'=>'数据库密码');
'mysql'=>'localhost',//数据库地址
'name'=>'root', //数据库登录名
'password'=>'', //数据库密码
'dbname'=>'lovewall'//数据库名
26 changes: 26 additions & 0 deletions admin/delete.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<?php
$id = !empty($_POST['id'])?$_POST['id']:'';
if (empty($id)) {
echo json_encode(['err'=>0]);
}
$conf = include "../require/conf.php";
$conn = mysqli_connect($conf['mysql'],$conf['name'],$conf['password']);

if(! $conn )
{
die('连接失败: ' . mysqli_error($conn));
}

// 设置编码,防止中文乱码
mysqli_query($conn , "set names utf8");

$sql = 'delete from '.$conf['table'].' where id = '.$id;

mysqli_select_db( $conn, $conf['dbname'] );
$retval = mysqli_query( $conn, $sql );
if ($retval) {
echo json_encode(['err'=>1]);
}else{
echo json_encode(['err'=>0]);
}
?>
78 changes: 78 additions & 0 deletions admin/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
<!DOCTYPE html>
<html lang="zh-CN">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<!-- 上述3个meta标签*必须*放在最前面,任何其他内容都*必须*跟随其后! -->
<title>Bootstrap 101 Template</title>

<!-- 最新版本的 Bootstrap 核心 CSS 文件 -->
<link rel="stylesheet" href="https://cdn.bootcss.com/bootstrap/3.3.7/css/bootstrap.min.css" integrity="sha384-BVYiiSIFeK1dGmJRAkycuHAHRg32OmUcww7on3RYdg4Va+PmSTsz/K68vbdEjh4u" crossorigin="anonymous">
<link rel="stylesheet" href="public/css.css">

<!-- HTML5 shim and Respond.js for IE8 support of HTML5 elements and media queries -->
<!-- WARNING: Respond.js doesn't work if you view the page via file:// -->
<!--[if lt IE 9]>
<script src="https://cdn.bootcss.com/html5shiv/3.7.3/html5shiv.min.js"></script>
<script src="https://cdn.bootcss.com/respond.js/1.4.2/respond.min.js"></script>
<![endif]-->
</head>
<body>
<div class="container" id="container">
<div class="row">
<table class="table">
<tr>
<th>标题</th>
<th>标题</th>
<th>标题</th>
<th>标题</th>
<th>标题</th>
</tr>
<?php
$conf = include "../require/conf.php";
$conn = mysqli_connect($conf['mysql'],$conf['name'],$conf['password']);

if(! $conn )
{
die('连接失败: ' . mysqli_error($conn));
}

// 设置编码,防止中文乱码
mysqli_query($conn , "set names utf8");

$sql = 'select * from '.$conf['table'];

mysqli_select_db( $conn, $conf['dbname'] );
$retval = mysqli_query( $conn, $sql );

if(! $retval )
{
die('无法读取数据: ' . mysqli_error($conn));
}

$res = mysqli_fetch_array($retval);
var_dump($res);exit;

while ($res = mysqli_fetch_array($retval)) {
?>
<tr>
<td class="active"><input type="checkbox"></td>
<td class="success"><?php echo $res['id']; ?></td>
<td class="warning"><?php echo date('Y-m-d',$res['data']); ?></td>
<td class="danger">...</td>
<td class="info">...</td>
<td class="info">...</td>
<td><button type="button" class="btn btn-danger">删除</button></td>
</tr>
<?php } ?>
</table>
</div>
</div>

<!-- jQuery (necessary for Bootstrap's JavaScript plugins) -->
<script src="https://cdn.bootcss.com/jquery/1.12.4/jquery.min.js"></script>
<!-- 最新的 Bootstrap 核心 JavaScript 文件 -->
<script src="https://cdn.bootcss.com/bootstrap/3.3.7/js/bootstrap.min.js" integrity="sha384-Tc5IQib027qvyjSMfHjOMaLkfuWVxZxUPnCJA7l2mCWNIpG9mGCD8wGNIcPD7Txa" crossorigin="anonymous"></script>
</body>
</html>
91 changes: 91 additions & 0 deletions admin/index.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
<!DOCTYPE html>
<html lang="zh-CN">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<!-- 上述3个meta标签*必须*放在最前面,任何其他内容都*必须*跟随其后! -->
<title>Bootstrap 101 Template</title>

<!-- 最新版本的 Bootstrap 核心 CSS 文件 -->
<link rel="stylesheet" href="https://cdn.bootcss.com/bootstrap/3.3.7/css/bootstrap.min.css" integrity="sha384-BVYiiSIFeK1dGmJRAkycuHAHRg32OmUcww7on3RYdg4Va+PmSTsz/K68vbdEjh4u" crossorigin="anonymous">


<!-- HTML5 shim and Respond.js for IE8 support of HTML5 elements and media queries -->
<!-- WARNING: Respond.js doesn't work if you view the page via file:// -->
<!--[if lt IE 9]>
<script src="https://cdn.bootcss.com/html5shiv/3.7.3/html5shiv.min.js"></script>
<script src="https://cdn.bootcss.com/respond.js/1.4.2/respond.min.js"></script>
<![endif]-->
</head>
<body>
<div class="container" id="container">
<div class="row">
<table class="table table-hover">
<tr>
<th>id</th>
<th>单身狗</th>
<th>单身狗的咆哮</th>
<th>单身狗的qq</th>
<th>单身狗的狗粮</th>
</tr>
<?php
include 'page.php';
@$allNum = allNews();
@$pageSize = 15; //约定没页显示几条信息
@$pageNum = empty($_GET["pageNum"])?1:$_GET["pageNum"];
@$endPage = ceil($allNum/$pageSize); //总页数
@$array = news($pageNum,$pageSize);
foreach($array as $key=>$values){
?>
<tr>
<td class="success"><?php echo $values->id; ?></td>
<td class="warning"><?php echo $values->name;?></td>
<td class="danger"><?php echo $values->text; ?></td>
<td class="info"><?php echo $values->qq; ?></td>
<td class="info"><?php echo date('Y-m-d',$values->date); ?></td>
<td><button type="button" data="<?php echo $values->id; ?>" class="btn btn-danger">删除</button></td>
</tr>
<?php } ?>
</table>

<?php

?>
</div>
<div class="row">
<div class="col-md-6 col-md-offset-4">
<ul class="pagination">
<li><a href="?pageNum=1">首页</a></li>
<li><a href="?pageNum=<?php echo $pageNum==1?1:($pageNum-1)?>">上一页</a></li>
<li><a href="?pageNum=<?php echo $pageNum==$endPage?$endPage:($pageNum+1)?>">下一页</a></li>
<li><a href="?pageNum=<?php echo $endPage?>">尾页</a></li>
</ul>
</div>
</div>

</div>

<!-- jQuery (necessary for Bootstrap's JavaScript plugins) -->
<script src="https://cdn.bootcss.com/jquery/1.12.4/jquery.min.js"></script>
<!-- 最新的 Bootstrap 核心 JavaScript 文件 -->
<script src="https://cdn.bootcss.com/bootstrap/3.3.7/js/bootstrap.min.js" integrity="sha384-Tc5IQib027qvyjSMfHjOMaLkfuWVxZxUPnCJA7l2mCWNIpG9mGCD8wGNIcPD7Txa" crossorigin="anonymous"></script>
<script>
$(function(){
$("button").click(function(){
var self = $(this).parent().parent();
var id = $(this).attr('data');
$.post("delete.php",
{ id: id } ,
function(data){
if(data.err != 0){
self.remove();
}else{
alert('删除失败');
}
},'json');
});
});
</script>
</body>
</html>
31 changes: 31 additions & 0 deletions admin/page.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
<?php
//分页的函数
function news($pageNum = 1, $pageSize = 3)
{
$array = array();
$coon = mysqli_connect("localhost", "root",'');
mysqli_select_db($coon, "lovewall");
mysqli_set_charset($coon, "utf8");
// limit为约束显示多少条信息,后面有两个参数,第一个为从第几个开始,第二个为长度
$rs = "select * from contents limit " . (($pageNum - 1) * $pageSize) . "," . $pageSize;
$r = mysqli_query($coon, $rs);
while ($obj = mysqli_fetch_object($r)) {
$array[] = $obj;
}
mysqli_close($coon,"lovewall");
return $array;
}

//显示总页数的函数
function allNews()
{
$coon = mysqli_connect("localhost", "root",'');
mysqli_select_db($coon, "lovewall");
mysqli_set_charset($coon, "utf8");
$rs = "select count(*) num from contents"; //可以显示出总页数
$r = mysqli_query($coon, $rs);
$obj = mysqli_fetch_object($r);
mysqli_close($coon,"lovewall");
return $obj->num;
}
?>
1 change: 0 additions & 1 deletion content/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
<?php do_html_head(""); ?>
<?php echo get_static_css ("i"); ?>
</head>

<body>
<div id="header">
<?php get_require_content("header"); ?>
Expand Down
6 changes: 6 additions & 0 deletions index.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,15 @@
// 需载入的页面类型
define("Pages",$_GET["pages"]);

//引入数据库配置文件
$conf = include 'require/conf.php';

// 载入函数表
require_once("require/function.php");

//声明字符集
header("Content-type: text/html; charset=utf-8");

// 载入主体
require_once("content/index.php");
?>
3 changes: 2 additions & 1 deletion require/ajax-function.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@ function insert_mysql_show ($sex,$mous,$say,$name,$qq){
if($qq != ""){
if(preg_match("/^[1-9]\d{4,10}$/",$qq)){
if($name != ""){
$conn=new mysqli(get_mysql("mysql"),get_mysql("name"),get_mysql("password"),get_mysql("name"));
$conn=new mysqli(get_mysql("mysql"),get_mysql("name"),get_mysql("password"),get_mysql("dbname"));
$conn->query("SET NAMES UTF8");//防止乱码
$stmt=$conn->prepare ("INSERT INTO contents (date,text,sex,qq,ip,mous,name) VALUES(?,?,?,?,?,?,?)");
$stmt->bind_param ("sssssss",time(),$say,$sex,$qq,get_client_ip (),$mous,$name);
$stmt->execute ();
Expand Down
7 changes: 7 additions & 0 deletions require/conf.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<?php
return [
'mysql'=>'localhost',//数据库配置
'name'=>'root',
'password'=>'',
'dbname'=>'lovewall'
];
5 changes: 3 additions & 2 deletions require/content-function.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,8 @@ function do_html_footer (){
/* 请不要更改此处内容 */
}
function do_html_content ($page,$mous){
$conn=new mysqli(get_mysql ("mysql"),get_mysql ("name"),get_mysql ("password"),get_mysql ("name"));
$conn=new mysqli(get_mysql ("mysql"),get_mysql ("name"),get_mysql ("password"),get_mysql ("dbname"));
$conn->query("SET NAMES UTF8");//防止乱码
if($page==""){
$limit=0;
}else{
Expand Down Expand Up @@ -100,7 +101,7 @@ function do_html_pages ($page,$mous){
}

// 计算全部页数
$conn=new mysqli(get_mysql ("mysql"),get_mysql ("name"),get_mysql ("password"),get_mysql ("name"));
$conn=new mysqli(get_mysql ("mysql"),get_mysql ("name"),get_mysql ("password"),get_mysql ("dbname"));
$x=0;
if ($mous==""){
$sql="SELECT * FROM contents";
Expand Down
10 changes: 7 additions & 3 deletions require/function.php
Original file line number Diff line number Diff line change
@@ -1,10 +1,14 @@
<?php
//因为不是面向对象写的 所以这里我就用了global 让$conf变成全局的变量
function get_mysql($biao) {
$mysql=array ('mysql'=>'数据库地址(默认localhost)','name'=>'数据库名称','password'=>'数据库密码');
return $mysql[$biao];
global $conf;
return $conf[$biao];
}

//这里设置了dbname为lovewall 本来这里是name 和数据库用户名相同了 以后还得把下面的数据库连接分离出来单独封装
function get_mysql_options($biao) {
$conn=new mysqli(get_mysql("mysql"),get_mysql("name"),get_mysql("password"),get_mysql("name"));
$conn=new mysqli(get_mysql("mysql"),get_mysql("name"),get_mysql("password"),get_mysql("dbname"));
$conn->query("SET NAMES UTF8");
$sql="SELECT * FROM options WHERE name='$biao'";
$result=$conn->query ($sql);
$row=$result->fetch_assoc ();
Expand Down
Loading