Thursday, February 19, 2015

PHP login page with MySQL database and validation

Here you will learn how to develop PHP login pagewith MySQL database. You may think sometimes what will happen when a user enters his credentials into any log-in page. Here the log-in process has been explained. This PHP login page with MySQL database connection and all the input parameters are validated with javascript. Comments have been added to make the understanding easy. You are always welcome with your doubts.
This is how the Login page looks on Browser
PHP login page with MySQL database and validation
login.php
01
02
03
04
05
06
07
08
09
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71

//Linking external stylesheet
 <link rel="stylesheet" type="text/css" href="../includes/style.css" media="screen" class="css-finalize-read">
 <title> Login</title>
 <br>
 
//Javascript for Validation of user inputs
 
<script type="text/javascript">
 function validate()
 {
 var x=document.forms["login"]["username"].value
 if (x==null || x=="")
 {
 alert("Username Cannot Be Left Blank.");
 return false;
 }
 var x=document.forms["login"]["password"].value
 if (x==null || x=="")
 {
 alert("password Cannot Be Left Blank.");
 return false;
 }
 else
 {
 return true;
 }
 }
 </script>
  
  
 
//Note the method type used is post and action page is logindatabase.php and also validate() function will be called on submit of the form.
 
<form name="login" method="post" action="logindatabase.php" onsubmit="return validate();">
 
<br><br><br><table border="3" width="355" align="center" bgcolor="#affeff">
 <tbody><tr class="alt"><td height="50" bgcolor="#aa0eff">
 <b>Login</b>
 </td></tr>
 
<tr>
 <td width="219">
 <br><table width="240" align="center">
 <tbody><tr class="alt"> </tr>
 <tr>
 <td width="71"><span style="font-size:12pt;">Username:</span></td>
 <td width="139"><input type="text" name="username" minlength="4" required="required" placeholder="Your username"></td>
 </tr>
 <tr class="alt">
 <td width="71"><span style="font-siz:12pt;">Password:</span></td>
 <td width="139"><input type="password" name="password" minlength="4" required="required" placeholder="Your Password"></td>
 </tr>
 
<tr>
 <td width="71"> </td>
 <td width="139">
 <p align="right"><input type="submit" name="submit" value="Submit">
 <input type="reset" name="reset" value="Reset"></p>
 </td>
 </tr>
 
</tbody></table>
 
</td>
 </tr>
 <tr class="alt">
 <td width="219" bgcolor="#aa0eff" align="center"><br>
 </td>
 </tr>
 
 


Read more >> PHP login page with MySQL database and validation

No comments:

Post a Comment