index.php
<!DOCTYPE html> <html lang="zh"> <head> <meta charset="UTF-8"> <meta http-equiv="X-UA-Compatible" content="IE=edge"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>Document</title> </head> <body> <form method="post" action="check.php" > <center>请输入记事内容</center> <textarea name="text" rows="5" cols="35" > </textarea><br> <input type="submit" value='保存' > </form> </body> </html>
check.php
<?php header("Content-type:text/html;charset=utf-8"); if($_POST['text']) { $text=$_POST['text']; $fp=fopen('./log.txt','a'); //a代表写入方式打开,如果文件不存在则创建//写入表单的内容 fwrite($fp,$text);//写入表单的内容 fclose($fp);//然后关闭文件 echo "<script>alert('保存成功!');location='index.php';</script>"; //提示保存成功,跳转到首页 } ?>
效果: