Monday, 15 February 2016

Text box validation on Key press

Dear All,
It is always mandatory to validate textbox in the keypress event. Please see the code

file name : validatetext.php


<html>
<head>
<!--
Coded by Prof. Sajeev Jaladharan
Date : 27.11.2015
email: sajeevjal@gmail.com
-->
<title>SNIT MCA Online Registration</title>

<script>
function checkname()
{

   
    /*if(!isNaN(name))
    {
        alert('Enter characters only');
        document.reg.Name.value='';
        document.reg.Name.focus();
    }
    */
        name=document.reg.Name.value;
   
    var letters = /^[A-Za-z]+$/; 
   if(name.match(letters)) 
     { 
      return true; 
     } 
   else 
     { 
     alert("No numbers or blank space please");
     document.reg.Name.value='';
        document.reg.Name.focus();
     return false; 
     } 
}



</script>
</head>
<body background="img.jpg" >
<table border=0 width=63% align="center" bgcolor="#EFFBFC">
<tr><td>

<form name="reg" class="wufoo topLabel page" method="post" action="saveadmission.php" onSubmit="return checkname()">
  <table style="border-color:#669999;border-style:dashed ;" align="center" cellpadding="2" cellspacing="2" width="85%">
    <tbody>
    <tr>
      <td>Name </td>
      <td><input id="Name" name="Name" style="width:150px" size="20" tabindex="2" type="text" onKeyUp="javascript:checkname()"></td></tr>
  
      <td colspan="2"><strong><blockquote class="style1"><span>For Communication Purpose</span></blockquote></strong></td></tr>
    <tr>
    
 
      <td colspan="2"><div align="center">
        <input name="Save" id="Save" value="Save Data" type="submit" tabindex="21">
        <label>
        <input name="Reset" value="Clear Form" type="reset">
        </label>
      </div></td></tr>
  </tbody></table>
  <div class="info" align="center">
</div>
</form>
</td></tr></table>
</body>
</html>

Thursday, 14 January 2016

Search using Ajax

Hi All,
Searching using Ajax is very important when we need to show the result in the same page without refreshing it.
It is composed of 2 steps

Step 1: Design the search page with Ajax function. Save this file as searchform.php

<html>
<head>
<script>
function loadDoc() {
//alert('HUP');
     var key=document.frmsearch.sname.value;
      var xhttp = new XMLHttpRequest();
      xhttp.onreadystatechange = function() {
        if (xhttp.readyState == 4 && xhttp.status == 200) {
             document.getElementById("demo").innerHTML = xhttp.responseText;
        }
  };
  xhttp.open("GET", "searchstud.php?key="+key, true);
  xhttp.send();
}
</script>


</head>
<body >
<form name=frmsearch  method=post>
<center>Name <input type=text name=sname onkeyup="loadDoc()"><input type=button value='Search Student'onclick="loadDoc()">
</center>
</form>
<div id="demo" align=center><h2>Search Result</h2></div>
</body>
</html>

Step2. PHP code to search in the database based on the Name field in Student table. Save this file as searchstud.php

<?php
$con=mysql_connect("localhost","root","");
mysql_select_db("SNIT",$con);
$sname=$_GET['key'];

$sql="Select * from student where name like '%$sname%'";



$data=mysql_query($sql,$con);
echo "<table border=1 align=center width=50%>";
echo "<tr><th>Name</th><th>Roll No</th><th>Marks</th></tr>";
while($row=mysql_fetch_array($data))
{
$name=$row['name'];
$rollno=$row['rollno'];
$marks=$row['marks'];

echo "<tr><td>$name</td><td>$rollno</td><td>$marks</td></tr>";

}

mysql_close($con);

?>

Working of this program

Here when we type in the textbox the 'onkeyup' event of textbox triggers the Ajax function 'loadDoc' which in turn make an http connection with the searching php program 'searchstud.php'.
The result generated by the php program will be send back to the searchform.php and updated in the area specified by the <div> tag in the same page. 










Wednesday, 13 January 2016

Searching using Form

Hi All,

Searching is most important in any student project.

This requires 5 important steps. [You can skip step 1,2 and 3 if you already have Database, table and data ]

1. Create Database - SNIT

Query : CREATE DATABASE SNIT

2. Create Table - student

Query : CREATE TABLE student(name TEXT(20),rollno int(3),marks int(3))

3. Insert few records in the table

Query : INSERT INTO `SNIT`.`student` (`name`, `rollno`, `marks`) VALUES ('Raju', '18', '90'), ('Babu', '9', '81')

4. Design Search form - save it as searchform.html

<html>
<body>
<form name=frmsearch action=searchstud.php method=post>
Name <input type=text name=sname><input type=submit value='Search Student'>
</form>
</body>
</html>

5. Write PHP program to search and display records. - save it as searchstud.php

<?php
$con=mysql_connect("localhost","root","");
mysql_select_db("SNIT",$con);
$sname=$_POST['sname'];
$sql="Select * from student where name like '%$sname%'";

echo $sql;

$data=mysql_query($sql,$con);
echo "<table border=1 align=center width=50%>";
echo "<tr><th>Name</th><th>Roll No</th><th>Marks</th></tr>";
while($row=mysql_fetch_array($data))
{
$name=$row['name'];
$rollno=$row['rollno'];
$marks=$row['marks'];

echo "<tr><td>$name</td><td>$rollno</td><td>$marks</td></tr>";

}

mysql_close($con);

?>

NB: Also try the same code with other table containing more fields

All the best.

Tuesday, 15 December 2015

PHP login, logout, user home page navigation

Dear Students,

It is really important to understand the flow of data once a user log to a system and use various links in the user home pages and finally log out of the sytem.
Step1 : login using home.php
Step2: Navigate to faculty home or student home or admin home based on the privileges set in the database
Step3: logout from the system.



Flow of program

home.php [type username and password] -->check.php[check for authentication and SQL Injection threat] ---> navigate to either facultyhome.php or adminhome.php or studenthome.php or home.php ->logout.php[when you click logout link]

NB: create a Database 'SNIT' and copy paste the below given sql in the SQL tab of phpmyadmin;


CREATE TABLE IF NOT EXISTS `login` (
  `username` text NOT NULL,
  `password` text NOT NULL,
  `type` text NOT NULL,
  `status` text NOT NULL
) ENGINE=MyISAM DEFAULT CHARSET=latin1;

--
-- Dumping data for table `login`
--

INSERT INTO `login` (`username`, `password`, `type`, `status`) VALUES
('admin', 'adm', 'admin', '1'),
('faculty', 'fac', 'faculty', '1'),
('student', 'stud', 'student', '1');

Check the system with these username, password pair 

For Admin  (admin,adm)
For Faculty (faculty,fac)
For Student  (student,stud)

home.php

 <html>
<!--
Authored by : Prof. Sajeev J. (sajeevjal@gmail.com)
Date : 16/12/2015
-->
<body>
<form id="form1" name="form1" method="post" action="check.php">
  <a name=#top>
  <table width="81%" border="0"  align="center">
 

    <tr>
      <td colspan="4"><div align="right">
        <label></label>
    <!-- Code to show error message if invalid username and password is typed -->  
     <?php
     $msg="";
    
     if($_GET['msg'])
     $msg=$_GET['msg'];
     if($msg=="Invalid Username or Password" || $msg=="You have not logged yet"|| $msg=="Your are not privilleged for this activity")
     echo "<font color=red >".$msg."</font>";
    
     ?></div></td>
      <td>&nbsp;</td>
    </tr>

    <tr>
      <td>&nbsp;</td>
      <td>&nbsp;</td>
      <td><div align="right">Username</div></td>
      <td><div align="right">
        <input type="text" name="username" />
      </div></td>
      <td>&nbsp;</td>
    </tr>
    <tr>
      <td>&nbsp;</td>
      <td>&nbsp;</td>
      <td><div align="right">Password</div></td>
      <td><div align="right">
        <input type="password" name="password" />
      </div></td>
      <td>&nbsp;</td>
    </tr>
    <tr>
      <td>&nbsp;</td>
      <td>&nbsp;</td>
      <td>&nbsp;</td>
      <td><div align="right">
        <input type="submit" name="Submit" value="Sign in" />
        <input type="reset" name="Submit2" value="Clear" />
      
      </div></td>
      <td>&nbsp;</td>
    </tr>
  </table>
</form>
</body>
</html>

check.php

<!--
Authored by : Prof. Sajeev J. (sajeevjal@gmail.com)
Date : 16/12/2015
-->
<?php

$username=$_POST['username'];
$password=$_POST['password'];

$count1=0; $count2=0;
$count1=substr_count($username, "'");
$count2=substr_count($password, "'");
$err=0;
if ($count1>0 || $count2>0)
    $err=1;

$con = mysql_connect("localhost","root","");
if (!$con)
  {
  die('Could not connect: ' . mysql_error());
  }
mysql_select_db("SNIT", $con);
$result = mysql_query("SELECT * from login where username='".$username."' and password='".$password."' and status='1'");
$flag=0;
while($row = mysql_fetch_array($result))
  {
 
  $flag=1;
  $type=$row['type'];
 
    session_start();
    $_SESSION['user'] = $type; // store session data
    $_SESSION['username'] = $username;



  }
 
 
  echo $flag;
  echo $type;
 
  if($err>0)
      echo "<script>location.href='home.php?msg=Invalid Username or Password'</script>";
    else if($flag==1 && $type=="admin")
  echo "<script>location.href='adminhome.php'</script>";
  else if($flag==1 && $type=="student")
  echo "<script>location.href='studenthome.php'</script>";
  else if($flag==1 && $type=="faculty")
  echo "<script>location.href='facultyhome.php'</script>";
 
  else
   echo "<script>location.href='labhome.php?msg=Invalid Username or Password'</script>";
 
mysql_close($con);
?>
adminhome.php
 <html >
<head>
<title>Admin Home</title>
<!--
Authored by : Prof. Sajeev J. (sajeevjal@gmail.com)
Date : 16/12/2015
-->
</head>
<body>
<h1>Admin Home</h1>
<a href=logout.php>Logout</a>
</body>
</html>

facultyhome.php

<html >
<head>
<!--
Authored by : Prof. Sajeev J. (sajeevjal@gmail.com)
Date : 16/12/2015
-->
<title>Faculty Home</title>
</head>
<body>
<h1>Admin Home</h1>
<table border=1>
<tr><td><a href='addstudent.php'>Add Student</a></td><td><a href='addparent.php'>Add Parent</td><td><a href='addmarks.php'>Enter Marks</a></td><td><a href=logout.php>Logout</a></td></tr>
</table>
</body>
</html>



studenthome.php

<html >
<head>
<title>Student Home</title>
<!--
Authored by : Prof. Sajeev J. (sajeevjal@gmail.com)
Date : 16/12/2015
-->
</head>
<body>
<h1>Student Home</h1>
<a href=logout.php>Logout</a>
</body>
</html>

logout.php

<!--
Authored by : Prof. Sajeev J. (sajeevjal@gmail.com)
Date : 16/12/2015
-->
<?php


session_start();
session_destroy();
echo "<script>location.href='home.php?msg=0'</script>";


?>

Thursday, 3 December 2015

File Reading and Tockeniser in PHP

Hi Friends,
Reading a file using PHP is pretty easy. Here is the code which read a text file and tockenize that line into words and displaying them in a formatted table format.

So we need two files. One is the text file (HUPFilestructure.txt) and another PHP file to process the same.

1. HUPFilestructure .txt

HUP HUP HUPA
HUPA HUP TFTKTU
TFTKTU HUP HUPA

2. PHP file (fileprocess.php)

<?php
$myfiles = fopen("HUPFileStructure.txt", "r") or die("Unable to open file!");
// Output one line until end-of-file
echo "<table border=1>";
while(!feof($myfiles))
{
  $row= fgets($myfiles); // Read line by line
 
  $tok = strtok($row, " "); // Tockenize that line using space
  echo "<tr>";
  while ($tok !== false)
  {
      echo "<td>$tok</td>";
    $tok = strtok(" ");
  }
  echo "</tr>";
}
echo "</table>";
fclose($myfiles);
?>

Tuesday, 1 December 2015

View registraion details in a table with alternate row color

Dear Friends,
You can display the details in the table with alternate row and text color using this code.

viewadmission.php


<html>
<head>
<title>
Registered Candidates
</title>
<body >
<!--
Coded by Prof. Sajeev Jaladharan
Date : 27.11.2015
email: sajeevjal@gmail.com
-->
<?php



$con = mysql_connect("localhost","root","");
if (!$con)
  {
      die('Could not connect: ' . mysql_error());
  }

mysql_select_db("snit",$con);
$result = mysql_query("SELECT * FROM student order by id");

?>
 <table width="81%" border="0"  align="center">
<tr>
      <td colspan="12" align="center" width='300'><img id=bg src="images/bgacademic.jpg"  /> </td>
     
     
    </tr>
<tr>
      <th>Id</th>
      <th>Name</th>
      <th>City</th>
      <th>State</th>     
      <th>Email</th>
      <th>LPhone</th>
      <th>Mobile</th>
      <th>Qualification</th>
      <th>Subject</th>
      <th>College</th>
     
    </tr>

<tr>
      <td>&nbsp;</td>
      <td>&nbsp;</td>
      <td>&nbsp;</td>
      <td>&nbsp;</td>
      <td>&nbsp;</td>
    </tr>

<?php
$i=-1;
while($row = mysql_fetch_array($result))
  {
    if($i==1)
    {
        $clr="#FFFFFF";       
        $tclr="#000000";
    }
    else
    {
        $clr="#666666";
        $tclr="#FFFFFF";
    }
    $i=$i * -1;

    echo "<tr>";
      echo "<td  bgcolor='$clr'><font color='$tclr'>".$row['id'] . "</font></td> ";
    echo "<td  bgcolor='$clr'><font color='$tclr'>".$row['Name'] . "</font></td> ";
    echo "<td  bgcolor='$clr'><font color='$tclr'>".$row['City'] . "</font></td> ";
      echo "<td bgcolor='$clr'><font color='$tclr'>".$row['State'] . "</font></td> ";
    echo "<td bgcolor='$clr'><font color='$tclr'>".$row['Email'] . "</font></td> ";
    echo "<td  bgcolor='$clr'><font color='$tclr'>".$row['Land'] . "</font></td> ";
      echo "<td bgcolor='$clr'><font color='$tclr'>".$row['Mobile1'] . "</font></td> ";
      echo "<td bgcolor='$clr'><font color='$tclr'>".$row['Qualification'] . "</font></td> ";
    echo "<td  bgcolor='$clr'><font color='$tclr'>".$row['Subject'] . "</font></td> ";
      echo "<td bgcolor='$clr'><font color='$tclr'>".$row['College'] . "</font></td> ";
   
    echo "</tr>";
  }

mysql_close($con);
?>


   
  
  </table>
  <div class="info" align="center">
    <h2>&nbsp;</h2>
</div>

<ul><p>&nbsp;</p>
<p>&nbsp;</p>
<p>&nbsp;</p>

</body>
</html>



Monday, 30 November 2015

Registration form with Java Script Validation and Id generation

Dear Friends,

Designing an HTML form with Java script validation and associated PHP code will eat much of our coding time. So a cut and paste code will prove to be useful in this regard.

Here the steps can be spitted to 3
1. Form creation and JS Validation
2. DB and Table creation
3. PHP Code to save it.

Step I. 
HMTL Code for the same - index.php


<html>
<head>
<!--
Coded by Prof. Sajeev Jaladharan
Date : 27.11.2015
email: sajeevjal@gmail.com
-->
<title>SNIT MCA Online Registration</title>

<script language="javascript" type="text/javascript">


function echeck(str) {

        var at="@"
        var dot="."
        var lat=str.indexOf(at)
        var lstr=str.length
        var ldot=str.indexOf(dot)
        if (str.indexOf(at)==-1){
           alert("Invalid E-mail ID")
           return false
        }

        if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr){
           alert("Invalid E-mail ID")
           return false
        }

        if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr){
            alert("Invalid E-mail ID")
            return false
        }

         if (str.indexOf(at,(lat+1))!=-1){
            alert("Invalid E-mail ID")
            return false
         }

         if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot){
            alert("Invalid E-mail ID")
            return false
         }

         if (str.indexOf(dot,(lat+2))==-1){
            alert("Invalid E-mail ID")
            return false
         }

         if (str.indexOf(" ")!=-1){
            alert("Invalid E-mail ID")
            return false
         }

          return true
    }


function checkform()
{
alert('HUP');

    if (document.reg.Name.value=="")
    {
        // something is wrong
        alert('Enter first name ');
        document.reg.Name.focus();
        return false;
    }
   
else if (document.reg.Housename.value=="")
    {
        // something is wrong
        alert('Enter Housename');
        document.reg.Housename.focus();
        return false;
}
else if (document.reg.Residence.value=="")
    {
        // something is wrong
        alert('Enter Addressline2 number');
        document.reg.Residence.focus();
        return false;
}
else if (document.reg.City.value=="")
    {
        // something is wrong
        alert('Enter City name');
        document.reg.City.focus();
        return false;
}
else if (document.reg.State.value=="")
    {
        // something is wrong
        alert('Enter State name');
        document.reg.State.focus();
        return false;
}
else if (document.reg.Pin.value=="")
    {
        // something is wrong
        alert('Enter Pin Number');
        document.reg.Pin.focus();
        return false;
}
else if ((document.reg.Email.value==null)||(document.reg.email.value==""))
{
        alert("Enter your Email ID");
        document.reg.Email.focus();
        return false;
}

else if(echeck(document.reg.Email.value)==false)
{

    alert('Enter email address properly \n[abc@abc.com]\nyourname@hostname.domainname\nExample:\nname@gmail.com');
    document.reg.Email.focus();
    return false;
}

else if (document.reg.Land.value=="")
    {
        // something is wrong
        alert('Enter Land phone information');
        document.reg.Land.focus();
        return false;
}
else if (document.reg.Mobile1.value=="")
    {
        // something is wrong
        alert('Enter Student Mobile phone information');
        document.reg.Mobile1.focus();
        return false;
}
else if (document.reg.Mobile2.value=="")
    {
        // something is wrong
        alert('Enter Parent Mobile phone information');
        document.reg.Mobile2.focus();
        return false;
}
else if (document.reg.Qualification.value=="")
    {
        // something is wrong
        alert('Enter Qualification information');
        document.reg.Qualification.focus();
        return false;
}
else if (document.reg.Subject.value=="")
    {
        // something is wrong
        alert('Enter Subject information');
        document.reg.Subject.focus();
        return false;
}

else if (document.reg.College.value=="")
    {
        // something is wrong
        alert('Enter College information');
        document.reg.College.focus();
        return false;
}
/* */
//document.reg.id.disabled=false;
return true;
}

</script>
</head>
<body background="img.jpg" >
<table border=0 width=63% align="center" bgcolor="#EFFBFC">
<tr><td>

<form name="reg" class="wufoo topLabel page" method="post" action="saveadmission.php" onSubmit="return checkform()">
  <table style="border-color:#669999;border-style:dashed ;" align="center" cellpadding="2" cellspacing="2" width="85%">
    <tbody>
    <tr>
      <td>Name </td>
      <td><input id="Name" name="Name" style="width:150px" size="20" tabindex="2" type="text"></td></tr>
   
      <td colspan="2"><strong><blockquote class="style1"><span>For Communication Purpose</span></blockquote></strong></td></tr>
    <tr>
      <td>House Name </td>
      <td><span class="full addr1">
        <input id="Housename" name="Housename" style="width:150px" class="field text addr" tabindex="6" type="text">
      </span></td></tr>
    <tr><td>Residence Name & No </td>
      <td><span class="full addr2">
        <input id="Residence" style="width:150px" name="Residence" class="field text addr" tabindex="7" type="text">
      </span></td></tr>
    <tr>
      <td>City</td>
      <td><span class="full addr1">
        <input id="City" name="City" style="width:150px" class="field text addr" tabindex="8" type="text">
      </span></td></tr>
    <tr><td>State</td>
      <td><span class="full addr2">
        <input id="State" style="width:150px" name="State" class="field text addr" tabindex="9" type="text">
      </span></td></tr>
    <tr>
      <td>Pin </td>
      <td><span class="left">
        <input id="Pin" style="width:150px" name="Pin" class="field text addr" maxlength="10" tabindex="10" type="text">
      </span></td></tr>
    <tr><td>Email Address </td>
      <td><span class="left">
        <input id="email" style="width:150px" name="Email" tabindex="11" class="field text addr" maxlength="27" type="text">
      </span></td></tr>
    <tr>
      <td colspan="2"><strong><blockquote class="style1"><span>Contact Numbers</span></blockquote></strong></td></tr>
    <tr>
      <td>Land number [put NA if No Land Phone] </td>
      <td><input id="Land" style="width:150px" name="Land" class="field text" size="15" maxlength="10" tabindex="12" type="text"></td></tr>
        <td>Mobile Number of Student </td>
          <td><input id="Mobile1" style="width:150px" name="Mobile1" class="field text" size="15" maxlength="13" tabindex="13" type="text"></td></tr>
  
<tr><td>Mobile Number of Parent </td>
          <td><input id="Mobile2" style="width:150px" name="Mobile2" class="field text" size="15" maxlength="13" tabindex="13" type="text"></td></tr>
     
    <tr bordercolor="#6699CC">
      <td colspan="2"><strong><blockquote class="style1"><span>Under Graduate Course Details</span></blockquote></strong></td></tr>
    <tr bordercolor="#6699CC">
      <td>Basic Qualification </td>
      <td><label>
        <select name="Qualification" id="Qualification"  tabindex="17" >
          <option selected="selected" value="BSC">BSC</option>
          <option value="BCA">BCA</option>
          <option value="BCOM">BCOM</option>
          <option value="Others">Others</option>
        </select>
      </label></td></tr>
    <tr><td>Degree Subject </td>
      <td><span class="     ">
        <input name="Subject" style="width:150px" id="Subject" type="text"  tabindex="18" >
      </span></td></tr>
   
    <tr><td>College of Current Study </td>
      <td><span class="     ">
        <input name="College" style="width:150px" id="College" type="text"  tabindex="20" >
      </span></td></tr>
  
      <td colspan="2"><div align="center">
        <input name="Save" id="Save" value="Save Data" type="submit" tabindex="21">
        <label>
        <input name="Reset" value="Clear Form" type="reset">
        </label>
      </div></td></tr>
  </tbody></table>
  <div class="info" align="center">
</div>
</form>
</td></tr></table>
</body>
</html>

Design
-------------

Step II
Creation of DB- Take phpmyadmin console and type the database name "snit" in the box provided. 
[NB: Database need to be created only once]
----------------------------------------------------------------------------------------------------


 Create Table
-----------------
SQL : 

CREATE TABLE IF NOT EXISTS `student` (
  `id` int(3) NOT NULL,
  `Name` tinytext NOT NULL,
  `Housename` tinytext NOT NULL,
  `Residence` tinytext NOT NULL,
  `City` tinytext NOT NULL,
  `State` tinytext NOT NULL,
  `Pin` tinytext NOT NULL,
  `Email` tinytext NOT NULL,
  `Land` tinytext NOT NULL,
  `Mobile1` tinytext NOT NULL,
  `Mobile2` tinytext NOT NULL,
  `Qualification` tinytext NOT NULL,
  `Subject` tinytext NOT NULL,
  `College` text NOT NULL
) ENGINE=MyISAM DEFAULT CHARSET=latin1;

After the creation of the Database, you click the SQL tab shown in the figure and copy the above SQL query and paste in the box provided in the screen and press GO.



Step III
PHP code to Save   -  saveadmission.php
------------------------------------------------------------------
<html >
<body>
<!--
Coded by Prof. Sajeev Jaladharan
Date : 27.11.2015
email: sajeevjal@gmail.com
-->
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>&nbsp;</p><p>&nbsp;</p>
<p>&nbsp;</p>
<p>&nbsp;</p><p>&nbsp;</p>
<p>&nbsp;</p>
<?php

$con = mysql_connect("localhost","root","");

if (!$con)
  {
  die('Could not connect: ' . mysql_error());
  }

mysql_select_db("snit",$con);


$Name=$_POST['Name'];

$Housename=$_POST['Housename'];

$Residence=$_POST['Residence'];

$City=$_POST['City'];

$State=$_POST['State'];

$Pin=$_POST['Pin'];

$Email=$_POST['Email'];

$Land=$_POST['Land'];

$Mobile1=$_POST['Mobile1'];

$Mobile2=$_POST['Mobile2'];


//email address is set as the username

$Qualification=$_POST['Qualification'];

$Subject=$_POST['Subject'];

$College=$_POST['College'];

$id=0;
$sql="select max(id)+1 as maxid from student";
$data=mysql_query($sql,$con);

while($row=mysql_fetch_array($data))
{
    $id=$row['maxid'];
}




$sql1="INSERT INTO `snit`.`student` (`id`, `Name`, `Housename`, `Residence`, `City`, `State`,`Pin`, `Email`, `Land`, `Mobile1`, `Mobile2`, `Qualification`, `Subject`, `College`) VALUES ('$id', '$Name', '$Housename', '$Residence', '$City', '$State', '$Pin', '$Email', '$Land', '$Mobile1', '$Mobile2', '$Qualification', '$Subject','$College')";


if (!mysql_query($sql1,$con))
  {
  die('Error: ' . mysql_error());

  }


echo "<center>Congrats...Your data saved. Thank you. Wishing you all the best </center>";
mysql_close($con);

?>


<p>&nbsp;</p><p>&nbsp;</p><p>&nbsp;</p><p>&nbsp;</p>
<p>&nbsp;</p>
<p>&nbsp;</p><p>&nbsp;</p>
<p>&nbsp;</p>
<p>&nbsp;</p><p>&nbsp;</p>
<p>&nbsp;</p>


</body>
<?php
echo "<script>alert('Thanks for Registration'); </script>";

echo "<script>location.href='index.php';</script>";
?>
</html>
 
 NB: Put these files in the project folder inside 'WWW' folder of WAMP/LAMP/XAMPP
mail me for more clarifications : sajeevjal@gmail.com