2020年5月8日
<?php
$post=$_POST;
var_dump($post);
include './functions.php';
$sql=sprintf("INSERT INTO comment VALUES(DEFAULT,'%s','%s','%s'),$post['comment'],$post['name'],$post['email']");
$res= execute($sql);
if($res){
echo"成功";
}else{
echo"失败"
}
function query($sql);
$link=mysqli_connect('127.0.0.1','root','root','liuyan')or exit('连接数据库失败');
mysqli_set_charset($link,'UTF8');
if($res≡false){
echo mysqli_errno($link),"<br>";
echo mysqli_error($link),"<br";
exit('sql语句执行失败');
}
$data=[];
while($row=mysqli_fetch_assoc($res)){
$data[]=$row;
}
mysqli_free_result($res);
mysqli_close($link);
return $data;
}
function execute($sql){
$link = mysqli_connect('127.0.0.1','root','root','liuyan')or exit('连接数据库失败');
mysqli_set_charset($link,'UTF8');
$res=mysqli_query($link,$sql);
$aff=mysqli_affected_rows($link);
mysqli_close($$link);
if($res && $aff > 0){
return true;
}else{
return false;
}
}
include '/.demo.php';
$sql="SELECT *FROM comment ORDER BY id DESC";
$data = query($sql);
?>
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>内容</title>
<styl>
</style>
</head>
<body>
<h1>留言板</h1>
<p>
<a herf="./add.php">添加留言</a>
</p>
<?php forseach($data as $key→$liuyan){ ?>
<div class="cb">
<p><? php echo $liuyan['content']?></p>
<div class="ca">
<b><? php echo $liuyan['name']?></b><span><?php echo $liuyan['email']?></span></div>
<div class="c-act">
<a herf="">编辑</a>
<a herf="">删除</a>
</div>
</div>
<?php } ?>
</body>
</html>
<?php
include './functions.php';
$sql="SELECT *FROM comment ORDER BY id DESC";
$data=query($sql);
?>
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>内容</title>
<styl>
.cb{
border:1px solid red;
}
</style>
</head>
<body>
<h1>留言板</h1>
<p><a herf="./add.php">添加留言</a></p>
<?php forseach($data as $key→$liuyan){ ?>
<div class="cb">
<p><? php echo $liuyan['content']?></p>
<div class="ca">
<b><? php echo $liuyan['name']?></b><span><?php echo $liuyan['email']?></span></div>
<div class="c-act">
<a herf="./edit.php?id=<?php echo $liuyan['id']?>">编辑</a>
<a herf="./del.php?id=<?php echo $liuyan['id']?>">删除</a>
</div>
</div>
<?php } ?>
</body>
</html>
<?php
$id=$_GET['id'];
var_dump($id);
$sql="DELETE FROM comment WHERE id={$id}";
include './functions.php';
$res=execute($sql);
if($res){
echo"成功";
}esle{
echo"失败“;
}
<?php
var_dump($_POST);
$id=$_POST['id'];
$content=$_POST['comment'];
$sql=sprintf("UPDATE comment SET content='%s' WHERE id =%s",$content,$id);
include './functions.php';
$res=execute($sql);
if($res){
echo"成功";
}else{
echo"失败";
}
<?php
$post=$_POST;
var_dump($post);
include './functions.php';
$sql=sprintf("INSERT INTO comment VALUES(DEFAULT,'%s','%s','%s'),$post['comment'],$post['name'],$post['email']");
$res= execute($sql);
if($res){
echo"成功";
}else{
echo"失败"
}
function query($sql);
$link=mysqli_connect('127.0.0.1','root','root','liuyan')or exit('连接数据库失败');
mysqli_set_charset($link,'UTF8');
if($res≡false){
echo mysqli_errno($link),"<br>";
echo mysqli_error($link),"<br";
exit('sql语句执行失败');
}
$data=[];
while($row=mysqli_fetch_assoc($res)){
$data[]=$row;
}
mysqli_free_result($res);
mysqli_close($link);
return $data;
}
function execute($sql){
$link = mysqli_connect('127.0.0.1','root','root','liuyan')or exit('连接数据库失败');
mysqli_set_charset($link,'UTF8');
$res=mysqli_query($link,$sql);
$aff=mysqli_affected_rows($link);
mysqli_close($$link);
if($res && $aff > 0){
return true;
}else{
return false;
}
}
include '/.demo.php';
$sql="SELECT *FROM comment ORDER BY id DESC";
$data = query($sql);
?>
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>内容</title>
<styl>
</style>
</head>
<body>
<h1>留言板</h1>
<p>
<a herf="./add.php">添加留言</a>
</p>
<?php forseach($data as $key→$liuyan){ ?>
<div class="cb">
<p><? php echo $liuyan['content']?></p>
<div class="ca">
<b><? php echo $liuyan['name']?></b><span><?php echo $liuyan['email']?></span></div>
<div class="c-act">
<a herf="">编辑</a>
<a herf="">删除</a>
</div>
</div>
<?php } ?>
</body>
</html>
<?php
include './functions.php';
$sql="SELECT *FROM comment ORDER BY id DESC";
$data=query($sql);
?>
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>内容</title>
<styl>
.cb{
border:1px solid red;
}
</style>
</head>
<body>
<h1>留言板</h1>
<p><a herf="./add.php">添加留言</a></p>
<?php forseach($data as $key→$liuyan){ ?>
<div class="cb">
<p><? php echo $liuyan['content']?></p>
<div class="ca">
<b><? php echo $liuyan['name']?></b><span><?php echo $liuyan['email']?></span></div>
<div class="c-act">
<a herf="./edit.php?id=<?php echo $liuyan['id']?>">编辑</a>
<a herf="./del.php?id=<?php echo $liuyan['id']?>">删除</a>
</div>
</div>
<?php } ?>
</body>
</html>
<?php
$id=$_GET['id'];
var_dump($id);
$sql="DELETE FROM comment WHERE id={$id}";
include './functions.php';
$res=execute($sql);
if($res){
echo"成功";
}esle{
echo"失败“;
}
<?php
var_dump($_POST);
$id=$_POST['id'];
$content=$_POST['comment'];
$sql=sprintf("UPDATE comment SET content='%s' WHERE id =%s",$content,$id);
include './functions.php';
$res=execute($sql);
if($res){
echo"成功";
}else{
echo"失败";
}
<?php
$post=$_POST;
var_dump($post);
include './functions.php';
$sql=sprintf("INSERT INTO comment VALUES(DEFAULT,'%s','%s','%s'),$post['comment'],$post['name'],$post['email']");
$res= execute($sql);
if($res){
echo"成功";
}else{
echo"失败"
}
function query($sql);
$link=mysqli_connect('127.0.0.1','root','root','liuyan')or exit('连接数据库失败');
mysqli_set_charset($link,'UTF8');
if($res≡false){
echo mysqli_errno($link),"<br>";
echo mysqli_error($link),"<br";
exit('sql语句执行失败');
}
$data=[];
while($row=mysqli_fetch_assoc($res)){
$data[]=$row;
}
mysqli_free_result($res);
mysqli_close($link);
return $data;
}
function execute($sql){
$link = mysqli_connect('127.0.0.1','root','root','liuyan')or exit('连接数据库失败');
mysqli_set_charset($link,'UTF8');
$res=mysqli_query($link,$sql);
$aff=mysqli_affected_rows($link);
mysqli_close($$link);
if($res && $aff > 0){
return true;
}else{
return false;
}
}
include '/.demo.php';
$sql="SELECT *FROM comment ORDER BY id DESC";
$data = query($sql);
?>
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>内容</title>
<styl>
</style>
</head>
<body>
<h1>留言板</h1>
<p>
<a herf="./add.php">添加留言</a>
</p>
<?php forseach($data as $key→$liuyan){ ?>
<div class="cb">
<p><? php echo $liuyan['content']?></p>
<div class="ca">
<b><? php echo $liuyan['name']?></b><span><?php echo $liuyan['email']?></span></div>
<div class="c-act">
<a herf="">编辑</a>
<a herf="">删除</a>
</div>
</div>
<?php } ?>
</body>
</html>
<?php
include './functions.php';
$sql="SELECT *FROM comment ORDER BY id DESC";
$data=query($sql);
?>
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>内容</title>
<styl>
.cb{
border:1px solid red;
}
</style>
</head>
<body>
<h1>留言板</h1>
<p><a herf="./add.php">添加留言</a></p>
<?php forseach($data as $key→$liuyan){ ?>
<div class="cb">
<p><? php echo $liuyan['content']?></p>
<div class="ca">
<b><? php echo $liuyan['name']?></b><span><?php echo $liuyan['email']?></span></div>
<div class="c-act">
<a herf="./edit.php?id=<?php echo $liuyan['id']?>">编辑</a>
<a herf="./del.php?id=<?php echo $liuyan['id']?>">删除</a>
</div>
</div>
<?php } ?>
</body>
</html>
<?php
$id=$_GET['id'];
var_dump($id);
$sql="DELETE FROM comment WHERE id={$id}";
include './functions.php';
$res=execute($sql);
if($res){
echo"成功";
}esle{
echo"失败“;
}
<?php
var_dump($_POST);
$id=$_POST['id'];
$content=$_POST['comment'];
$sql=sprintf("UPDATE comment SET content='%s' WHERE id =%s",$content,$id);
include './functions.php';
$res=execute($sql);
if($res){
echo"成功";
}else{
echo"失败";
}