I do not know PHP, but I will give you an example of how I would do it with vbscript (classic asp), so you can try to adapt it to PHP as needed.
In my applications, I do not use the form tag since I used ajax first. So here we go:
login html page: include jquery <script type='text/javascript' src='your-jquery-url'></script> <script type='text/javascript'> function tryLogin() { var inputs='userName='+$('logInUsername').val()+ '&userPassw='+$('logInPassword').val(); //notice that I changed your name= to id= in the form //notice the '&' in the '&userPassw= $.post('your-login-validation-page',inputs,function(data) { eval('var json='+data); if (json['success'] == 'true') { $('#loginForm').html('<p>Congratulations! You\'ve been logged in successfully</p>') } else { alert(json['errorMessage']); $('#logInUsername').focus(); } }); } </script> <div id='loginForm' > <label for="login">User Name</label> <input type="text" id="logInUsername" /> <label for="Password">Password</label> <input type="password" id="logInPassword" /> <button onClick='tryLogin(); ' >LOGIN</button> </div> login-validation-page [in vbscript] user = request.Form("userName") passw = request.Form("userPassw") "if is there this user" (coded as if there was a database look up...) "if the password = passw" (coded as comparing the values) response.write "{'sucess':'true'}" else response.write "{'success':'false','errorMessage':'wrong password'}" end if else response.write "{'success':'false','errorMessage':'user not found'}" end if ---> end of login-validation-page
zequinha-bsb
source share