Click here to Skip to main content
15,889,838 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
I want my first output to remain on the screen while i output another username to stay under the first output, instead php replace my previous with new username submited. please help a brother, I'm Lost.

//HTML CODE BELOW









//PHP CODE BELOW


What I have tried:

//HTML CODE BELOW

<form action="bot.php" method="POST">
		
		<input type="text" name="username" required=""/>
		
		<input type="submit" name="submit" value="submit"/>
	</form>


//PHP CODE BELOW
<?php
	
	//request name from form
	 $username= $_REQUEST['username'];
	 
	 //create function
	 function msg(){
		
		$username=$_POST['username'];
		echo "$username";
		echo "\r\n";
	}
	 
	 //ourting input to screen
	 
	 if(isset($_POST['submit'])){
		 
		 msg();
	 }
	 		
?>
Posted
Comments
Richard MacCutchan 24-Jun-22 3:09am    
You should build a list containing the information you want to display, and add each new name to the end of the list. You can then use the contents of the list to write a table on your displayed web form.
Member 15627495 24-Jun-22 3:15am    
the echo() function buffers the output ( your page ),
just echo the first $username.

in your php code,
you use $username twice, so the second value take the place of the first username.

you have several solutions :
echo $username instead of putting the value in a var.
or
fill an array(0=>user1 , 1 => user 2 ..... )
or
rename a var :
like :
$from working well with $to .. for your 2 people talking each other.
Jeffersonballer 24-Jun-22 6:02am    
Thank you very much friend, seems you understand what I'm trying to do, please can you write a demo code for me, I'm just a php beginner.. I'll appreciate if you can.. Much love

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