Tuesday, February 1, 2011

Detecting the Clicked Submit Button

Assalamualaikum n selamat sejahtera

This post will discuss about more on previous post.So,as we can see that when we first load the page ,the text is already display like this:

"You're not a member" is display on first load,although we do not click the submit button yet.So,to solve this we just add this code:

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

on our script.A little explanation on that line,that isset() is a inbuilt function that use to checks if a variable has been set or not.In our case,we will checks the value of Submit button.So,if we first load or reload the page not refresh but reload it,then there is no value will be set for the Submit button.If we click the Submit button,then the PHP set the Submit button.Besides there is a reason why i type SubmitOne is it because the name of my Submit button is SubmitOne.

<INPUT TYPE = "Submit"  Name = "SubmitOne"   VALUE = "Login">

So change our code at PHP side to be like this:

<?PHP
if (isset ($_POST['SubmitOne']) )
{

$username = $_POST['username'];

if ($username == "master") {
print ("Welcome back, master!");
}

else {
print ("You're not a member...");
}

}
?>

The new code is in bold and red text.

N/NOTE:Miss one character,you re out!so check it!before u run it.Any question?

No comments:

Post a Comment