基本上我只想让用户进入网站,输入他们的消息和名称,结果应该显示在同一页面中,当另一个用户再次进入时,以前用户的结果应该在那里,任何来的应该只是添加到列表中.
目前我有:
<form id="form1" name="form1" method="post" action="">
<label>Please type in a message
<input type="text" name="msg" id="msg" />
</label>
<label>and your name
<input type="text" name="pin" id="name" />
</label>
<p>
<label>Submit
<input type="submit" name="submit" id="submit" value="Submit" />
</label>
</p>
</form>
<?php
$msg = $_POST[msg];
$name = $_POST[name];
?>
<br />
<?php echo "$msg"?>
<?php echo "$name"?>
Run Code Online (Sandbox Code Playgroud)
但当输入另一条记录时,前一条记录丢失了......
提前致谢
这应该做你想要的.它加载以前的帖子posts.txt,添加当前帖子,显示帖子并保存.您需要确保posts.txt存在且具有正确的权限.
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
</head>
<body>
<form id="form1" name="form1" method="post" action="">
<label>Please type in a message
<input type="text" name="msg" id="msg" />
</label>
<label>and your name
<input type="text" name="name" id="name" />
</label>
<p>
<label>Submit
<input type="submit" name="submit" id="submit" value="Submit" />
</label>
</p>
</form>
<?php
$msg = $_POST["msg"];
$name = $_POST["name"];
$posts = file_get_contents("posts.txt");
$posts = "$msg - $name\n" . $posts;
file_put_contents("posts.txt", $posts);
echo $posts;
?>
</body>
</html>
Run Code Online (Sandbox Code Playgroud)