2-9作业编辑功能 提交没反应
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 | <?php header( "Content-type:text/html;charset=utf-8;" ); date_default_timezone_set( "PRC" ); $edkey = $_GET [ "edkey" ]; $filename = "msg.txt" ; $msgs =[]; if ( file_exists ( $filename )){ $string = file_get_contents ( $filename ); if ( strlen ( $string )>0){ $msgs =unserialize( $string ); //如果有内容就把反序列化一下 } $edarr = $msgs [ $edkey ]; if (! is_array ( $edarr ) || count ( $edarr )<=0){ echo "<script>alert('编辑错误 ,无法编辑');location.href='index.php';</script>" ; } } ?> <!DOCTYPE HTML> <html> <head> <meta http-equiv= "Content-Type" content= "text/html; charset=utf-8" /> <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> <small><span>编辑留言</span>v1.0</small> </h1> </div> <div class = "hero-unit" > <h1> Hello, world! </h1> <p> 这是一个可视化布局模板, 你可以点击模板里的文字进行修改, 也可以通过点击弹出的编辑框进行富文本修改. 拖动区块能实现排序. </p> </div> <form action= "index.php" method= "post" > <fieldset> <legend>发布留言</legend> <label>用户名</label><input class = "form-control" type= "text" name= "username" required value= "<?php echo $edarr['username']?>" /> <label>标题</label><input class = "form-control" type= "text" name= "title" required value= "<?php echo $edarr['title']?>" /> <label>内容</label><textarea name= "content" rows= "6" cols= "4" required value= "" ><?php echo $edarr [ 'content' ]?></textarea> <label></label><button type= "submit" name= "pubmsg" class = "btn" >编辑完成</button> <a href= "index.php" ><button type= "submit" class = "btn" >查看留言</button></a> </fieldset> <input type= "hidden" name= "edkey" id= "" value= "<?php echo $edkey ?>" /> </form> </div> </div> </div> </body> </html> |
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 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 | <?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 ); //如果存在就读取这个文件内容 并且赋值给string if ( strlen ( $string )>0){ $msgs =unserialize( $string ); //如果有内容就把反序列化一下 } } if (isset( $_POST [ "sub" ])){ $username = $_POST [ "username" ]; $title = strip_tags ( $_POST [ "title" ]); //strip_tags()去除用户填写 html和php标记 注入 $content = strip_tags ( $_POST [ "content" ]); $time =time(); //将以上的post过来的数据组成关联数组; $data =compact( "username" , "title" , "content" , "time" ); //把关联数组数据插入$msgs array_push ( $msgs , $data ); //在把序列化一下,变成字符串 用于存储 $msgs =serialize( $msgs ); //像filename 中写入 内容 if ( file_put_contents ( $filename , $msgs )){ echo "<script>alert('留言成功');location.href='index.php'</script>" ; } else { echo "<script>alert('留言失败');location.href='index.php'</script>" ; } } if (isset( $_POST [ "pubmsg" ])){ $username = $_POST [ "username" ]; $title = strip_tags ( $_POST [ "title" ]); //strip_tags()去除用户填写 html和php标记 注入 $content = strip_tags ( $_POST [ "content" ]); $time =time(); //将以上的post过来的数据组成关联数组; $data =compact( "username" , "title" , "content" , "time" ); //把关联数组数据插入$msgs //array_push($msgs,$data); //替换数组的 //array_replace($msgs,$data); //在把序列化一下,变成字符串 用于存储 $msgs =serialize( $msgs ); //像filename 中写入 内容 if ( file_put_contents ( $filename , $msgs )){ echo "<script>alert('编辑成功');location.href='index.php'</script>" ; } else { echo "<script>alert('编辑失败');location.href='index.php'</script>" ; } } ?> <!DOCTYPE HTML> <html> <head> <meta http-equiv= "Content-Type" content= "text/html; charset=utf-8" /> <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> <small><span>留言板-</span>v1.0</small> </h1> </div> <div class = "hero-unit" > <h1> Hello, world! </h1> <p> 这是一个可视化布局模板, 你可以点击模板里的文字进行修改, 也可以通过点击弹出的编辑框进行富文本修改. 拖动区块能实现排序. </p> </div> <?php if ( is_array ( $msgs )&& count ( $msgs )>0): ?> <table class = "table" > <thead> <tr> <th> 编号 </th> <th> 用户 </th> <th> 标题 </th> <th> 时间 </th> <th> 内容 </th> <th> 操作 </th> </tr> </thead> <tbody> <?php $i =1; foreach ( $msgs as $key => $val ): ?> <tr class = "success" > <td> <?php echo $i ++; ?> </td> <td> <?php echo $val [ "username" ]; ?> </td> <td> <?php echo $val [ "title" ]; ?> </td> <td> <?php echo @ date ( "Y/m/d H:i:s" , $val [ "time" ]); ?> </td> <td> <?php echo $val [ "content" ]; ?> </td> <td> <a href= "edit.php?edkey=<?php echo $key ?>" >编辑</a> | <a href= "delete.php?delekey=<?php echo $key ?>" >删除</a> </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" rows= "" cols= "" required></textarea> <label></label><button type= "submit" name= "sub" class = "btn" >提交</button> </fieldset> </form> </div> </div> </div> </body> </html> |
42
收起
正在回答 回答被采纳积分+1
3回答
恭喜解决一个难题,获得1积分~
来为老师/同学的回答评分吧