170311php添加留言页面
1.添加留言页面
1 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" 2 "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> 3 <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en"> 4 <head> 5 <meta http-equiv="Content-Type" content="text/html;charset=UTF-8"> 6 <title>Document</title> 7 </head> 8 <body> 9 <h2>添加留言页面</h2> 10 <form action="doAction.php" method="get"> 11 <input type="hidden" name="act" value="add"/> 12 <table border="1" width="80%" cellpadding="0" cellspacing="0" bgcolor="blue"> 13 <tr> 14 <td>留言者</td> 15 <td><input type="text" name="username" id="" placholder="请输入您的昵称"/></td> 16 </tr> 17 <tr> 18 <td>标题</td> 19 <td><input type="text" name="title" id="" placholder="请输入您的标题"/></td> 20 </tr> 21 <tr> 22 <td>日志</td> 23 <td><textarea name="content" id="" cols="45" rows="10"></textarea></td> 24 </tr> 25 <tr> 26 <td>心情</td> 27 <td> 28 <input type="radio" name="xinqing" value="xinqing1" checked="checked" ><img src="img/1.jpg" alt="" width="50" height="50"/> 29 <input type="radio" name="xinqing" value="xinqing2" ><img src="img/1.jpg" alt="" width="50" height="50"/> 30 <input type="radio" name="xinqing" value="xinqing3"><img src="img/1.jpg" alt="" width="50" height="50"/> 31 <input type="radio" name="xinqing" value="xinqing4" ><img src="img/1.jpg" alt="" width="50" height="50"/> 32 </td> 33 </tr> 34 <tr> 35 <td colspan="2"><input type="submit" value="提交"/></td> 36 </tr> 37 </table> 38 </form> 39 </body> 40 </html>
2.doAction.php页面
1 <?php 2 /** 3 * Created by PhpStorm. 4 * User: liaoxiaofeng 5 * Date: 2017/3/11 6 * Time: 11:10 7 */ 8 $username=isset($_GET['username'])?$_GET['username']:''; 9 $title=isset($_GET['title'])?$_GET['title']:''; 10 $content=isset($_GET['content'])?$_GET['content']:''; 11 $xinqing=isset($_GET['xinqing'])?$_GET['xinqing']:''; 12 $time=date('Y-m-d h:i:s'); 13 $act=isset($_GET['add'])?$_GET['add']:''; 14 $filename="text.txt"; 15 //来到doAction页面的时候先做一个判断1.text.txt文件 2.文件里面有没有数据 16 //3.有数据把text.txt里的数据取出来 17 if(file_exists($filename)&&filesize($filename)>0){ 18 //从text.txt里面取数据 19 $str= file_get_contents($filename); 20 //通过反序列化把字符转化成为我们的二维数组 21 //$arr=unserialize($str); 22 } 23 if($act=='add'){ 24 25 $arr[]=array( 26 'username'=>$username, 27 'title'=>$title, 28 'content'=>$content, 29 'xinqing'=>$xinqing, 30 'time'=>$time 31 ); 32 $arr=serialize($arr); 33 file_put_contents($filename,$arr); 34 // print_r($arr); 35 }
3.更新留言
1 <?php 2 $filename='text.txt'; 3 ?> 4 <!DOCTYPE html> 5 <html> 6 <head lang="en"> 7 <meta charset="UTF-8"> 8 <title>用户列表页</title> 9 </head> 10 11 <body> 12 <h3 style="text-align:center;">用户列表页</h3> 13 <table style="margin:0 auto;border:1px solid;width:80%;"> 14 <tr style="text-align:center;"> 15 <td>编号</td> 16 <td>标题</td> 17 <td>内容</td> 18 <td>留言者</td> 19 <td>发布时间</td> 20 <td>心情</td> 21 </tr> 22 <?php foreach ($userInfo as $key => $val){ 23 ?> 24 <tr style="text-align:center;"> 25 <td><?php echo $key; ?></td> 26 <td><?php echo $val['title'] ?></td> 27 <td><?php echo $val['content']; ?></td> 28 <td><?php echo $val['username']; ?></td> 29 <td><?php echo $val['time']; ?></td> 30 <td><img src="img/1.jpg" width="50" height="50"/><?php echo $val['xinqing']; ?></td> 31 </tr> 32 <?php } 33 ?> 34 35 </table> 36 37 38 </body> 39 </html>