i want to make a add cricket stats page (witch i have done) but when i fill in the form and press submit i made it say echo "$name stats have been added";
but when i add a new persons stats that dispersers and is re开发者_运维技巧placed by a different the one i just made, how can i make it stay every time i add a new one so i can see who's stats i have added?
Create an array of names stored in $_SESSION
and keep adding to it on each post. Then display them all each time.
session_start();
// Initialize the array
if (!isset($_SESSION['names'])) {
$_SESSION['names'] = array();
}
// Add the newest name to the array
$_SESSION['names'][] = $name;
// Display them all in a loop with linebreaks
foreach ($_SESSION['names'] as $cur_name) {
echo "$cur_name stats have been added<br />\n";
}
EDIT:
To reset them, pass ?action=reset
in the URL querystring as www.example.com?action=reset
<form action='scriptname.php' method="get">
<input type="hidden" name="action" value="reset" />
<input type="submit" value="Reset list" />
</form>
// Remove the session array on reset.
if (isset($_GET['action']) && $_GET['action'] == "reset")
{
unset($_SESSION['names']);
}
why dont you just insert the new name you wanna add, into your DB ? and make a select when you wanna view some names
精彩评论