Databases| SQL| MySQL| Questions?

 

 

 

 

 

 

 

 

 

 

 

 

 

Search Tutorials

Latest Questions
Comments
 
PHP SQL Login 
 

This Application illustrates how to create a login page where only authorized user can login and process further.

 

PHP SQL Login

                         

This Application illustrates how to create a login page where only authorized user can login and process further.

In this application, we have created a userlogin.php page which has a form with two input fields and one submit button. In this form, we validate  whether both input field are filled or not. If the input field is blank then an alert message will be displayed. If user fills the correct credentials then loginaction.php page will is called which works as the action page where we check both field from database table whether user name and password is available in the database table or not. If user name and password have been validated then user is sent to the welcome.php page and if the user is not authorized then to the error.php page with error message and a link for come back on userlogin.php page.

 

 

 

Source Code of userlogin.php 

<html>
  <title>User Login Page</title>
  <head>
  <script language="JavaScript">
  function validateForm(theForm){
    if(theForm.userid.value ==""){
      alert("Enter the name");
      theForm.userid.focus();
      return false;
    }
    if(theForm.password.value==""){
      alert("enter the password");
      theForm.password.focus();
      return false;
    }
    return true;
  }
  </script>
  </head>

  <body>
    <table border="1" cellspacing="0" cellpadding="0">
    <h2>Login Form</h2>
    <form method="POST" action="loginaction.php" onsubmit="return validateForm(this);">
      <font size="2"> <strong> Enter username and Password: </strong></font>
      <tr>
        <td><b> UserName</b></td>
        <td><input type="text" size="20" name="userid"></td><br>
      </tr>
      <tr>
        <td><b> Password </b></td>
        <td><input type="password" size="20" name="password"></td>
      </tr><br>
      <tr>
        <td><input type="submit" name="submit" value="submit"></td>
      </tr>
    </form>
  </body>  
  </table>
</html>

 

Source Code of loginaction.php 

<?
  if!isset($_SESSION) ) { session_start()}
  $database_db="test";
  $user_db="root";
  $password_db="root";
  $host_db="localhost";

  $link=mysql_connect($host_db,$user_db,$password_dbor die ("couldnot connect: ".mysql_error());
  mysql_select_db($database_db, $link)  or exit('Error Selecting database: '.mysql_error()); ;
  
  $userid=$_POST["userid"];
  $password=$_POST["password"];

  $errormessage = "";

  $sql="SELECT * FROM users  where username='$userid' and password='$password'";
  $result = mysql_query($sql, $link)  or exit('$sql failed: '.mysql_error())
  $num_rows = mysql_num_rows($result);
  if($num_rows==0){
    header("Location: error.php");
  else {
    header("Location: welcome.php");
    exit;
  }
?>

 

welcome.php

<h2>Login Success...</h2>

error.php

<h2>Login Failed...</h2>
<a href="userlogin.php">login again</a>

Download Source Code

Output:

 

                         

» View all related tutorials
Related Tags: sql mysql c string com function fun io sed const char int ai padding length character case cas if ie

Leave your comment:

Name:

Email:

URL:

Title:

Comments:


Enter Code:

Audio Version
Reload Image
 

Note: Emails will not be visible or used in any way, and are not required. Please keep comments relevant. Any content deemed inappropriate or offensive may be edited and/or deleted.

No HTML code is allowed. Line breaks will be converted automatically. URLs will be auto-linked. Please use BBCode to format your text.

Add This Tutorial To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Training Courses
Tell A Friend
Your Friend Name
Software Solutions
Least Viewed
Most Rated
Recently Viewed
Search Tutorials

 

 
 

Home | JSP | EJB | JDBC | Java Servlets | WAP  | Free JSP Hosting  | Search Engine | News Archive | Jboss 3.0 tutorial | Free Linux CD's | Forum | Blogs

About Us | Advertising On RoseIndia.net  | Site Map

India News

Indian Software Development Company | iPhone Development Company in India | Flex Development Company in India | Java Training Delhi | Java Training at Noida |

Send your comments, Suggestions or Queries regarding this site at roseindia_net@yahoo.com.

Copyright © 2008. All rights reserved.