Tuesday, February 1, 2011

Keeping display the data that user entered

Assalamualaikum and selamat sejahtera

So,as we already learn in previous post,when we enter our username and click the submit button,the textbox will reset to its initial value which is "username".For example,

before we enter the username:


after we enter the username and clicked the login button,the textbox is reset to "username":

 
So,for this post we will learn on how to keep the our username in the textbox after we click the login button.
Its easy!hehehe,okey we just modify the PHP script like this (the bold n red text is the new code):

<?PHP

if (isset($_POST['SubmitOne']) ) {

$username = $_POST['username'];

if ($username == "master") {
print ("Welcome back, master!");
}
else {
print ("You're not a member...");
}}

else
{$username ="";}

?>

For the new code,else statement,we're just setting the value of $username for when the button is NOT clicked.For example, when the page is refreshed.

Just try it,like:
$username ="Username?";

but before run it,we will modify a little bit on HTML form (the bold n red text is the new code):

<body>
<FORM NAME ="formOne" METHOD ="POST" ACTION = "">
<INPUT TYPE = "Text" VALUE="<?PHP print $username ; ?>" NAME = "username">
<INPUT TYPE = "Submit"  Name = "SubmitOne"   VALUE = "Login">
</FORM>
</body>


N/NOTE:However, there are some security issues associated with textboxes.Soon we will learn on how to handle this in a later section

No comments:

Post a Comment