<?php
@mysql_connect("127.0.0.1:3306","root","") or die("mysql数据库连接失败");
@mysql_select_db("test")or die("db连接失败");
mysql_query("set names 'gbk'");
?>
<a href="index.php"><B>index</B></a>
<a href="add.php"><B>add blog</B></a>
<hr>
<?php
include("conn.php"); //引入连接数据库
if (!empty($_POST['sub'])) {
$title = $_POST['title']; //获取title表单内容
$con = $_POST['con']; //获取contents表单内容
$sql= "insert into blog values(null,'0','$title',now(),'$con')";
mysql_query($sql);
echo "insert success!";
}
?>
<form action="add.php" method="post">
title :<br>
<input type="text" name="title"><br><br>
contents:<br>
<textarea rows="5" cols="50" name="con"></textarea><br><br>
<input type="submit" name="sub" value="submit">
</form>
<a href="index.php"><B>index</B></a>
<a href="add.php"><B>add blog</B></a>
<br><br>
<form action="" method="get" style='align:"right"'>
<input type="text" name="keys" >
<input type="submit" name="subs" >
</form>
<hr>
<?php
include("conn.php"); //引入连接数据库
if (!empty($_GET['keys'])) {
$key = $_GET['keys'];
$w = " title like '%$key%'";
}else{
$w=1;
}
$sql ="select * from blog where $w order by id desc limit 5";
$query = mysql_query($sql);
while ($rs = mysql_fetch_array($query)) {
?>
<h2>title: <a href="view.php?id=<?php echo $rs['id']; ?>"><?php echo $rs['title']; ?></a>
| <a href="edit.php?id=<?php echo $rs['id']; ?>">edit</a>
| <a href="del.php?id=<?php echo $rs['id']; ?>">delete</a> |
</h2>
<li>date: <?php echo $rs['data']; ?></li>
<!--截取内容展示长度-->
<p>contents:<?php echo iconv_substr($rs['contents'],0,30,"gbk"); ?>...</p>
<hr>
<?php
};
?>
<a href="index.php"><B>index</B></a>
<a href="add.php"><B>add blog</B></a>
<hr>
<?php
include("conn.php"); //引入连接数据库
if (!empty($_GET['id'])) {
$id = $_GET['id'];
$sql ="select * from blog where id='$id' ";
$query = mysql_query($sql);
$rs = mysql_fetch_array($query);
$sqlup = "update blog set hits=hits+1 where id='$id'";
mysql_query($sqlup);
}
?>
<h2>title: <?php echo $rs['title']; ?> </h1>
<h3>date: <?php echo $rs['data']; ?>
click number: <?php echo $rs['hits']; ?></h3>
<hr>
<p>contents:<?php echo $rs['contents']; ?></p>
<a href="index.php"><B>index</B></a>
<a href="add.php"><B>add blog</B></a>
<hr>
<?php
include("conn.php"); //引入连接数据库
//获取数据库表数据
if (!empty($_GET['id'])) {
$edit = $_GET['id'];
$sql = "select * from blog where id='$edit'";
$query = mysql_query($sql);
$rs = mysql_fetch_array($query);
}
//更新数据库表数据
if (!empty($_POST['sub'])) {
$title = $_POST['title']; //获取title表单内容
$con = $_POST['con']; //获取contents表单内容
$hid = $_POST['hid'];
$sql= "update blog set title='$title', contents='$con' where id='$hid' ";
mysql_query($sql);
echo "<script>alert('update success.');location.href='index.php'</script>";
}
?>
<form action="edit.php" method="post">
<input type="hidden" name="hid" value="<?php echo $rs['id'];?>">
title :<br>
<input type="text" name="title" value="<?php echo $rs['title'];?>">
<br><br>
contents:<br>
<textarea rows="5" cols="50" name="con" ><?php echo $rs['contents'];?></textarea><br><br>
<input type="submit" name="sub" value="submit">
</form>
<a href="index.php"><B>index</B></a>
<a href="add.php"><B>add blog</B></a>
<hr>
<?php
include("conn.php"); //引入连接数据库
if (!empty($_GET['id'])) {
$del = $_GET['id']; //删除blog
$sql= "delete from blog where id='$del' ";
mysql_query($sql);
echo "delete success!";
}
?>
机械节能产品生产企业官网模板...
大气智能家居家具装修装饰类企业通用网站模板...
礼品公司网站模板
宽屏简约大气婚纱摄影影楼模板...
蓝白WAP手机综合医院类整站源码(独立后台)...苏ICP备2024110244号-2 苏公网安备32050702011978号 增值电信业务经营许可证编号:苏B2-20251499 | Copyright 2018 - 2025 源码网商城 (www.ymwmall.com) 版权所有