I am a rookie in PHP and have just started learning the basics of this language.
I have created a page login.php that contains a text field and a password field. What I want to do is, on the click of the submit button, I want to call a PHP method, authenticateUser() that I have defined on the same page. If the user is successfully authenticated, then he is directed to the index.html page. If not, then he remains on the same page and an error message pops up saying that the username/password is incorrect. All of this logic has been defined in the authenticateUser() function. I haven't included the code over here for security purposes.
The problem is that the button resides on the client side and the PHP script resides on the server side. Can anyone please tell me how can I achieve this? The source code for login.php is given below. Thank you in advance.
login.php
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Login</title>
</head>
<body>
<?php function authenticateUser($username,$password) { //Code to check the user 's credentials
}
?>
<form id="form1" name="form1" method="post" action="index.php">
<input name="txtUsername" type="text" id="txtUsername" size="30" maxlength="100" />
<input name="txtPassword" type="password" id="txtPassword" size="30" maxlength="100" />
<input type="submit" name="btnLogin" id="btnLogin" value="Log In" />
</form>
</body>
</html>