Click here to Skip to main content
15,897,891 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
hi every one i am using this code please any body confirm me why text box values blank after click on submit button.
<?php echo'<html>
<body>

<form action="index.php" method="post">
Name: <input type="text" name="name" />
Age: <input type="text" name="age" />
<input type="submit" name="submit" value="submit" />
</form>

</body>
</html>';
 if(isset($_POST["submit"]))
{
    
	if($_POST["name"]=="")
	{
	echo "Enter Name...";
	exit();}
		if($_POST["age"]=="")
	{
	echo "Enter age...";
	exit();}
	echo $_POST["name"].'<br/>';
	echo $_POST["age"];
}	
?>
Posted
Updated 6-May-13 23:04pm
v2

Check the source of the html. You are writing the values past the end of the actual html document (after the ). View the source of the response html and you might find the values at the end.

Good luck!
 
Share this answer
 
Comments
E.F. Nijboer 7-May-13 5:32am    
Then you need to put the value back in the textbox. Something like:
<input type="text" name="name" value="<?php print $_POST["name"]; ?>" />
because page is going refresh
Happy Coding!
:)
 
Share this answer
 
Comments
Aarti Meswania 7-May-13 5:28am    
Check this link...
http://stackoverflow.com/questions/7589880/how-to-make-browser-not-to-refresh-full-page-when-it-goes-to-url

or you can put values in viewstate then set them back to related control after page refreshed
AJAX can help to prevent refreshing of your page hence preserving your data!
 
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