Simple html / php form for output to the same page

Basically, I want users to go to the site, enter their message and name, and the results should be displayed on one page, and when another user comes back, the results from the previous user should be there and everything that comes should just be added to list.

I currently have:

 <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 entry is entered, the previous one is lost ...

early

+5
source share
7 answers

, . 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>
+7

, . sql , , . , , , .

+3

. - , . -, . , - -, .

, MySQL. / , ( nth ) .

0

, . , . , .

0

. MySQL - , , . . , .

0

, . , ?

<input type="text" value="<?php (isset($_POST[msg])) ? $_POST[msg] : "" ?>" name="msg" id="msg" />
0

:

$first = $_POST['msg'];
$second = $_POST['pin'];

post, .

-, , -, MySQL. . .

Probably the easiest thing for you is to add to the text file (if it's a simple application).

This should help you get started.

0
source

All Articles