简单的html/php表单可在同一页面上输出 [英] Simple html/php form to output on the same page

查看:273
本文介绍了简单的html/php表单可在同一页面上输出的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

基本上,我想要的只是让用户进入该网站,键入他们的消息和名称,结果应该显示在同一页面上,并且当另一个用户再次进入时,前一个用户的结果应该在那里出现的所有内容都应添加到列表中.

Basically all I want is for users to come into the site, type in their message and name, and the results should be displayed in the same page and when another user comes in again, the results from previous user should be there and anything that comes up should just be added to the list.

目前我有:

 <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"?>

但是当输入另一条记录时,上一条将丢失...

but when another record is type in, the previous one is lost...

预先感谢

推荐答案

这应该做您想要的.它从posts.txt加载以前的帖子,添加当前帖子,显示并保存.您需要确保posts.txt存在并且具有正确的权限.

This should do what you want. It loads previous posts from posts.txt, adds the current one, displays the posts and saves it. You'll need to make sure posts.txt exists and has correct permissions.

<!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>

这篇关于简单的html/php表单可在同一页面上输出的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆