php留言本

<!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 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>

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值