Header Ads

Create simple student management system using PHP with MySQL

Part 1

This tutorial is for php beginners who already known about the fact in php and mysql database syntax. In this Part 1: We are going to create the login.php form to logging into student management website.

login.php

<form action="<?php echo $_SERVER['PHP_SELF'];?>" method="post">
<table>
<tr>
    <td>Username</td>
        <td><input type="text" name="username" /></td></tr>
    <tr>
    <td>Password</td>
<td><input type="password" name="password" /></td></tr>
    <tr>
    <td>&nbsp;</td>
    <td><input type="button" name="btnLogin" value="Login" /></td></tr>        
</table>
</form>


After creating the logging form we have to validate the form using php syntax.
login.php

<?php
$error="";
if(isset($_POST['btnLogin']) and $_POST['btnLogin']="Login")
{

//Process login
$username = $_POST['username'];
$password = $_POST['password'];
include "db.php";
$sql = "select * from user where username='$username'  and password=md5('$password')";
$results  = mysql_query($sql) or die("Error on application: ".mysql_error());
$rowcount = mysql_num_rows($results);
if($rowcount>0)
{
//User Available
session_start();
$_SESSION['user']=$user;
header("Location:index.php");

}  
else
{
//Invalied User 
$error="Invalid Username or Password";
}
}
?>


If you give either wrong username or a password, this page gives an error as Invalid Username or Password.

<form action="<?php echo $_SERVER['PHP_SELF'];?>" method="post">
<table>
<tr>
     <td>Username</td>
        <td><input type="text" name="username" /></td></tr>
    <tr>
     <td>Password</td>
<td><input type="password" name="password" /></td></tr>
    <tr>
     <td>&nbsp;</td>
     <td><input type="button" name="btnLogin" value="Login" /><?php echo $error; ?></td></tr>        
</table>
</form>

Create table called 'user' in your mysql database. Fill password column(remember to set md5 function to your password)

You want to save also the db.php file as well. Here it is.
db.php

<?php
$dbuser = "root";
$dbpassword = "";
$db       = "students";
$host     = "localhost";
$conn = mysql_connect($host,$dbuser,$dbpassword) or die("Unable to connect to the database: ". mysql_error());
mysql_select_db($db) or die("Unable to Select the database: ".mysql_error());
?>



When after giving the username and password correclty you can log into your index page.
index.php

<?php
session_start();
if(isset($_SESSION['user']))
{
?>
#################### BODY ##############


<?php
}
else
{
header("Location:login.php");
}
?>

login.php : see full view

Note: Hope to post Part II soon. Any problem about the application please be kind enough to inform me. Wish you best luck ! 

11 comments:

  1. Thank you for checking the post about php. Most of the visitors have been visiting under php in this site. So, anyone wants to know about the steps after creating this simple php site. Further more, do you want to add extra features for your student mgt system application? please respond!

    Comment what you're thinking about, please....

    ReplyDelete
  2. Please upload simple registration form which is connecting with MySQL database and a member logging by getting data from that same MySQL table.

    ReplyDelete
    Replies
    1. http://itechdigest.blogspot.com/2013/07/create-member-log-in-after-sign-up.html

      Delete
  3. http://itechdigest.blogspot.com/2013/07/create-member-log-in-after-sign-up.html

    Here I post something about what you are looking for.

    ReplyDelete
  4. thanks for those codes pls..
    how about part two

    -what about an admin panel and users(student panel)
    -students can see their results, calculate their grades,
    lecturers can view students results after being inputed,search for a student, search a list of students,... print and submit

    ReplyDelete
    Replies
    1. Thanks for your comment Mr.Pius :) .. You can download simple student mgt system full code here:

      http://www.4shared.com/zip/Skzm_PIJ/Student_Registeration_I.html

      Delete
  5. Replies
    1. -- phpMyAdmin SQL Dump
      -- version 3.4.5
      -- http://www.phpmyadmin.net
      --
      -- Host: localhost
      -- Generation Time: Apr 11, 2012 at 11:02 AM
      -- Server version: 5.5.16
      -- PHP Version: 5.4.0beta2-dev

      SET SQL_MODE="NO_AUTO_VALUE_ON_ZERO";
      SET time_zone = "+00:00";


      /*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */;
      /*!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS */;
      /*!40101 SET @OLD_COLLATION_CONNECTION=@@COLLATION_CONNECTION */;
      /*!40101 SET NAMES utf8 */;

      --
      -- Database: `students`
      --

      -- --------------------------------------------------------

      --
      -- Table structure for table `student`
      --

      CREATE TABLE IF NOT EXISTS `student` (
      `id` int(11) NOT NULL AUTO_INCREMENT,
      `nic` varchar(255) NOT NULL,
      `name` varchar(255) NOT NULL,
      `address` varchar(255) NOT NULL,
      `birthday` date NOT NULL,
      `telephone` int(11) NOT NULL,
      `email` varchar(255) NOT NULL,
      PRIMARY KEY (`id`)
      ) ENGINE=InnoDB DEFAULT CHARSET=latin1 AUTO_INCREMENT=6 ;

      --
      -- Dumping data for table `student`
      --

      INSERT INTO `student` (`id`, `nic`, `name`, `address`, `birthday`, `telephone`, `email`) VALUES
      (1, '334', 'Ranil, 'Sentana', '1444', 444, 'ans.sdf@gmail.com'),
      (2, '101', 'Nimal Perera', 'Katugasthota', '1976-04-02', 71, 'nimal@gmail.com'),
      (3, '134', 'Kamal Fernando', 'Mathara', '1976-03-19', 78, 'Kamal@gmail.com'),
      (5, '234', 'Sunil Madushanka', 'Nugegoda', '1980-02-19', 0, '');

      -- --------------------------------------------------------

      --
      -- Table structure for table `user`
      --

      CREATE TABLE IF NOT EXISTS `user` (
      `userid` int(11) NOT NULL AUTO_INCREMENT,
      `username` varchar(255) NOT NULL,
      `password` varchar(255) NOT NULL,
      PRIMARY KEY (`userid`)
      ) ENGINE=InnoDB DEFAULT CHARSET=latin1 AUTO_INCREMENT=2 ;

      --
      -- Dumping data for table `user`
      --

      INSERT INTO `user` (`userid`, `username`, `password`) VALUES
      (1, 'admin', '202cb962ac59075b964b07152d234b70');

      /*!40101 SET CHARACTER_SET_CLIENT=@OLD_CHARACTER_SET_CLIENT */;
      /*!40101 SET CHARACTER_SET_RESULTS=@OLD_CHARACTER_SET_RESULTS */;
      /*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */;

      Delete
    2. Thank you, really helpful

      Delete
  6. http://itechdigest.blogspot.com/2014/05/create-employee-management-system-using.html

    Good project for university student. thank you!

    ReplyDelete

Thank you very much for your ideas!