php留言本
2015-10-24 10:50
627 查看
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>留言本</title> </head> <body> <form action="write.php" method="post"> <p>留言标题:<input type="text" name="title" /></p> <p>留言内容:<textarea name="content" id="" cols="30" rows="10" > </textarea></p> <p><input type="submit" value="提交" /></p> </form> </body></html>
-----------------write.php-------------
<?php
//print_r($_POST);
$fh=fopen('./msg.txt','a');
$str=$_POST['title'].','.$_POST['content']."\n";
fwrite($fh,$str);
fclose($fh);
echo 'ok';
-------------msg.php--------------------
<?php
$fh=fopen('./msg.txt','r');
$i=1;
while($row=fgetcsv($fh)){
echo '<li>'.'<a href=./readmsg.php?tid=',$i,' />'.$row[0].'</li>';
$i++;
}
------------------readmsg.php--------------
<?php
$tid=$_GET['tid'];
$fh=fopen('./msg.txt','r');
$i=1;
while($row=fgetcsv($fh)){
if($i==$tid){
print_r($row);
}
$i++;
}
**********************数据库形式*********************
---------------write.php------------------
<?php
$conn = mysqli_connect("localhost", "root", "123456", "test");
if (!$conn) {
die("连接失败" . mysql_error());
} else {
echo "Success!";
}
mysqli_query($conn, "set names utf8");
$sql="insert into message (title,content,pubtime) VALUES ('".$_POST['title']."',
'".$_POST['content']."',".time().")";
echo $sql."<br/>";
if($res = mysqli_query($conn, $sql)){
echo "留言成功";
}else{
echo "留言失败";
}
?>
---------------------msg.php---------------------------
<?php
$conn = mysqli_connect("localhost", "root", "123456", "test");
mysqli_query($conn, "set names utf8");
$sql="select * from
d891
message";
$res = mysqli_query($conn, $sql);
//var_dump($res);
while($row=mysqli_fetch_assoc($res)){
//print_r($row);
echo '<li>','<a href=readmsg.php?id=',$row['id'],' />',$row['title'].'</li>';
}
-----------------------readmsg.php-----------------------
<?php
$conn = mysqli_connect("localhost", "root", "123456", "test");
mysqli_query($conn, "set names utf8");
$id=$_GET['id'];
$sql="select * from message where id=".$id;
$res = mysqli_query($conn, $sql);
$row=mysqli_fetch_assoc($res);
?>
<h1><?php echo $row['title'];?></h1>
<p><?php echo $row['content'];?></p>
相关文章推荐
- 一个关于if else容易迷惑的问题
- PHP5.2.*防止Hash冲突拒绝服务攻击的Patch
- 深入理解PHP之匿名函数
- JSP/PHP基于Ajax的分页功能实现
- 关于PHP通过PDO用中文条件查询MySQL的问题。
- 什么是设计模式
- PHP数据库长连接mysql_pconnect的细节
- Php Installing An Expansion
- PHP+Apache在Windows 9x下的安装和配置
- IIS 6 的 PHP 最佳配置方法
- 安装Apache和PHP的一些补充
- Linux Apache+MySQL+PHP
- 建立Apache+PHP+MySQL数据库驱动的动态网站
- PHP 5.3.0 安装分析心得
- apache 环境下 php 的配置注意事项
- ASP.NET、ASP、PHP、JSP之间有什么区别?
- PHP VBS JS 函数 对照表
- C语言实现的统计php代码行数功能源码(支持文件夹、多目录)
- php xml 入门学习资料