以为我也会插话。这是一个简单的解决方案,仅适用于页面的当前实例。
<?php
if ( isset( $_POST['text'] ) ) { # Find out if the form had been submitted
$text = $_POST['text']; # If so then store the submitted text in the $text var
if ( isset( $_POST['previous'] ) ) { # Find out if there were any previous inputs
$current = $_POST['previous'] . "," . $_POST['text']; # If there were then pop the latest one on the end of the previous ones with a comma and make that our current set of text
} else {
$current = $_POST['text']; # Otherwise the current set of text just comprises our most recently input text
}
}
?>
<html>
<div>
<?php
if ( isset( $_POST['text'] ) ) { # Find out if some text was input
$text_arr = explode(",", $current); # If it was then take our current set of text and make an array from it
echo "<ul>"; # Start the list
foreach ( $text_arr as $text ) { # For each item of text that has previously been input
echo "<li>".$text."</li>"; # Print out the list item with the text in it
}
echo "</ul>"; # End our list
}
?>
</div>
<form method="POST" action="<?php echo $_SERVER['PHP_SELF'];?>">
<?php if ( isset( $_POST['text'] ) ) { ?> # If the previous form submitted some text
<input type="hidden" name="previous" value="<?php echo $current ?>" /> # Store it in a hidden input field to be submitted later
<?php } ?>
Name: <input type="text" name="text" /><br/>
<input type="submit" value="Submit" />
</form>
</html>
所以这将做你想要的,但没有任何存储到数据库中。如果您想要存储到数据库中,那么您可能需要对 MySQL 或其他永久存储列表项的方法进行一些研究。
希望我的帮助有所帮助,我敢肯定,在我输入此内容时,许多其他人已经给出了答案...