助教你不回答 我只好又来提问了 点击提交之后表格不显示 是哪写错了?找不到啊
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 | <?php header( 'content-type:text/html;charset=utf-8' ); date_default_timezone_set( 'PRC' ); $filename = "msg.txt" ; $msgs =[]; if ( file_exists ( $filename )){ $string = file_get_contents ( $filename ); if ( strlen ( $string >0)){ $msgs =unserialize( $string ); } } //检测用户是否点击了按钮 if (isset( $_POST [ 'pubmsg' ])){ $username = $_POST [ 'username' ]; $title = $_POST [ 'title' ]; $content = $_POST [ 'content' ]; $time =time(); $data =compact( 'username' , 'title' , 'content' , 'time' ); array_push ( $msgs , $data ); $msgs =serialize( $msgs ); //序列号变成字符串 if ( file_put_contents ( $filename , $msgs )){ echo "<script>alert('留言成功!');location.href='webpage.php';</script>" ; } else { echo "<script>alert('留言失败!');location.href='webpage.php';</script>" ; } } ?> <!DOCTYPE html> <html> <head> <script type= "text/javascript" src= "http://www.francescomalagrino.com/BootstrapPageGenerator/3/js/jquery-2.0.0.min.js" ></script> <script type= "text/javascript" src= "http://www.francescomalagrino.com/BootstrapPageGenerator/3/js/jquery-ui" ></script> <link href= "http://www.francescomalagrino.com/BootstrapPageGenerator/3/css/bootstrap-combined.min.css" rel= "stylesheet" media= "screen" > <script type= "text/javascript" src= "http://www.francescomalagrino.com/BootstrapPageGenerator/3/js/bootstrap.min.js" ></script> </head> <body> <div class = "container-fluid" > <div class = "row-fluid" > <div class = "span12" > <div class = "page-header" > <h1> this is Pan show time </h1> </div> <?php if ( is_array ( $msgs )&& count ( $msgs )>0):?> <table class = "table" > <thead> <tr> <th> 编号 </th> <th> 用户 </th> <th> 标题 </th> <th> 时间 </th> <th> 内容 </th> </tr> </thead> <tbody> <?php $i =1; foreach ( $msgs as $val ):?> <tr class = "success" > <td> <?php echo $i ++; ?> </td> <td> <?php echo $var [ 'username' ]; ?> </td> <td> <?php echo $var [ 'title' ]; ?> </td> <td> <?php echo date ( "Y-m-d H:i:s" , $var [ 'time' ]);?> </td> <td> <?php echo $val [ 'content' ];?> </td> </tr> <?php endforeach ; ?> </tbody> </table> <?php endif ;?> <form action= "#" method= "post" > <fieldset> <legend>留言处</legend> <label>用户名</label> <input type= "text" name= "username" required> <label>标题</label> <input type= "text" name= "title" required> <label>内容</label> <textarea name= "content" cols= "30" rows= "5" required></textarea> <hr color= "pink" > <button type= "submit" name= "pubmsg" class = "btn" >提交</button> </fieldset> </form> </div> </div> </div> </body> </html> |
源自:数组运用
2-12 留言板功能实现
40
收起
正在回答 回答被采纳积分+1
5回答
慕移动4345823
2017-07-14 13:49:49
你看看第9行, if(strlen($string>0)){ 应该改成 if(strlen($string)>0){ strlen()函数算好$string的长度再和0比较
Joper
2017-07-11 14:52:31
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 | <?php header( 'content-type:text/html;charset=utf-8' ); date_default_timezone_set( 'PRC' ); $filename = "msg.txt" ; $msgs =[]; if ( file_exists ( $filename )){ $string = file_get_contents ( $filename ); if ( strlen ( $string >0)){ $msgs =unserialize( $string ); } } //检测用户是否点击了按钮 if (isset( $_POST [ 'pubmsg' ])){ $username = $_POST [ 'username' ]; $title = $_POST [ 'title' ]; $content = $_POST [ 'content' ]; $time =time(); $data =compact( 'username' , 'title' , 'content' , 'time' ); array_push ( $msgs , $data ); $msgs =serialize( $msgs ); //序列号变成字符串 if ( file_put_contents ( $filename , $msgs )){ echo "<script>alert('留言成功!');location.href='1.php';</script>" ; } else { echo "<script>alert('留言失败!');location.href='1.php';</script>" ; } } ?> <!DOCTYPE html> <html> <head> <script type= "text/javascript" src= "http://www.francescomalagrino.com/BootstrapPageGenerator/3/js/jquery-2.0.0.min.js" ></script> <script type= "text/javascript" src= "http://www.francescomalagrino.com/BootstrapPageGenerator/3/js/jquery-ui" ></script> <link href= "http://www.francescomalagrino.com/BootstrapPageGenerator/3/css/bootstrap-combined.min.css" rel= "stylesheet" media= "screen" > <script type= "text/javascript" src= "http://www.francescomalagrino.com/BootstrapPageGenerator/3/js/bootstrap.min.js" ></script> </head> <body> <div class = "container-fluid" > <div class = "row-fluid" > <div class = "span12" > <div class = "page-header" > <h1> this is Pan show time </h1> </div> <?php if ( is_array ( $msgs )&& count ( $msgs )>0):?> <table class = "table" > <thead> <tr> <th> 编号 </th> <th> 用户 </th> <th> 标题 </th> <th> 时间 </th> <th> 内容 </th> </tr> </thead> <tbody> <?php $i =1; foreach ( $msgs as $val ):?> <tr class = "success" > <td> <?php echo $i ++; ?> </td> <td> <?php echo $var [ 'username' ]; ?> </td> <td> <?php echo $var [ 'title' ]; ?> </td> <td> <?php echo date ( "Y-m-d H:i:s" , $var [ 'time' ]);?> </td> <td> <?php echo $val [ 'content' ];?> </td> </tr> <?php endforeach ; ?> </tbody> </table> <?php endif ;?> <form action= "#" method= "post" > <fieldset> <legend>留言处</legend> <label>用户名</label> <input type= "text" name= "username" required> <label>标题</label> <input type= "text" name= "title" required> <label>内容</label> <textarea name= "content" cols= "30" rows= "5" required></textarea> <hr color= "pink" > <button type= "submit" name= "pubmsg" class = "btn" >提交</button> </fieldset> </form> </div> </div> </div> </body> </html> |
恭喜解决一个难题,获得1积分~
来为老师/同学的回答评分吧