Click here to Skip to main content
15,885,546 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
hi.
i want to create an HTML form with a name like foo.php with a username textbox so that it Submits the username to php part of the code on the same file.
and then in the php part of file it show all the usernames listed. without using a Database or javascript.
when i submit the code then username is listed.but when i submit another username then the previous username is cleared on the list and the new one is shown.when i want to use an array to save the username in it then it resets the contents of the variable after i click submit.i have attached the picture of what i want.

the picture of what i really mean

here's the code:

HTML
<form action="index.php" method="get">
Username:<input type="text"  name="uname" /><br />
<input type="submit" />
<input type="reset" />
</form>

PHP
$username=@$_GET['uname'];
echo '<table border="1"> <tr> <td>'.$username.' </td> </tr>  </table><br>';
}
Posted
Updated 10-Apr-15 2:04am
v3

That is the very nature of web, it is state-less. It doesn't remember your previous visit. The solution is to use a session variable as an array to store the submitted name of each postback:
PHP
session_start();

if(!isset($_SESSION['name’])) {
   $_SESSION['name’]=array();
} else {
   array_push($_SESSION[‘name’], $_GET["username"]);
}

foreach($_SESSION[‘name’] as $name){
   echo $name."<br>;
}


Learn more about
1. PHP Session Variable[^]
2. PHP Array[^]
3. PHP foreach[^]
 
Share this answer
 
v4
WOW.it really works.to be honest i have no experience in web design and php.i used to program in delphi and VB but i'm still a beginner in PHP and HTML.
i really appreciate your help.
i have another question.what i want is to add a button to add every usename entry one by one and then use another button to send all the entered usernames to php altogether.
something like this picture:

Here's a picture of what i mean
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900