Header Ads

Create simple student management system using PHP with MySQL part 2

This section will give you the basic PHP script to build your Student Management System. Please go through carefully. Don't copy and paste the commands, go through one by one and understand why the script is coming and what does the script do. If you have any doubts, don't hesitate to reach us.






link with http://itechdigest.blogspot.in/2012/09/create-simple-student-management-system.html

register.php

<?php
session_start();
$err_nic="";
$err_name="";
$err_address="";
$err_bithday="";
$error=-1;
$msg="";
$nic="";
$name="";
$address="";
$day="";
$month="";
$year="";
$telephone="";
$email="";
function isEmpty($val)
{
if(strlen($val)==0)
{
return true;
}
else
{
return false;
}
}
function isSelected($val,$sval)
{
if ($val==$sval)
{
return 'selected="selected"';
}
}

if(isset($_SESSION['user']))
{
if(isset($_POST['btnSave']))
{
$error=0;
//User Clicked on Save Button
$nic=$_POST['txtNIC'];
$name=$_POST['txtName'];
$address=$_POST['txtAddress'];
$day=$_POST['ddlDay'];
$month=$_POST['ddlMonth'];
$year=$_POST['ddlYear'];
$telephone=$_POST['txtTelephone'];
$email=$_POST['txtEmail'];

//Validations
if(isEmpty($nic))
{
$error=1;
$err_nic="Please Enter  NIC";
}

if(isEmpty($name))
{
$error=1;
$err_name="Please Enter  Name";
}

if(isEmpty($address))
{
$error=1;
$err_address="Please Enter  Address";
}
if($day==-1 or $month==-1 or $year==-1)
{
$error=1;
$err_bithday="Please Select Correct Date";
}
if($error==0)
{
//Procees Save
$count=0;
include "../db.ini.php";
$bday="$year-$month-$day";
$sql="INSERT INTO STUDENT(NIC,NAME,ADDRESS,BIRTHDAY,TELEPHONE,EMAIL)
     VALUES('$nic','$name','$address','$bday','$telephone','$email')";
   mysql_query($sql) or die(mysql_error());
$count=mysql_affected_rows($conn);
if($count>0)
{
$msg="Record Saved";
}
else
{
$msg="Record Not Saved";
}
}
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>..:: Student Management ::..</title>
</head>

<body>
<table width="100%" border="0">
  <tr>
    <td colspan="2"><div align="center">
      <h2>Student Management</h2>
    </div></td>
  </tr>
  <tr>
    <td colspan="2">&nbsp;</td>
  </tr>
  <tr>
    <td width="30%" valign="top"><?php include "leftnav.php"; ?></td>
    <td width="70%"><form id="form1" name="form1" method="post" action="<?php echo $_SERVER['PHP_SELF']; ?>">
      <table width="500" border="0" bgcolor="#00FFFF">
        <tr>
          <td colspan="2"><div align="center">
            <h4><strong>Student Redidtration</strong></h4>
          </div></td>
          </tr>
        <tr>
          <td width="96"><strong>NIC</strong></td>
          <td width="294"><input name="txtNIC" type="text" id="txtNIC" size="12" maxlength="10" value="<?php echo $nic;?>" />          <span style="color:#FF0000;font-size:9px"><?php echo $err_nic; ?></span>          </td>
        </tr>
        <tr>
          <td><strong>Name</strong></td>
          <td><input name="txtName" type="text" id="txtName" size="40" maxlength="100" value="<?php echo $name;?>"/><span style="color:#FF0000;font-size:9px"><?php echo $err_name; ?></span></td>
        </tr>
        <tr>
          <td valign="top"><strong>Address</strong></td>
          <td><textarea name="txtAddress" id="txtAddress" cols="50" rows="4"><?php echo $address; ?></textarea><span style="color:#FF0000;font-size:9px"><?php echo $err_address; ?></span></td>
        </tr>
        <tr>
          <td><strong>Birthday</strong></td>
          <td><table width="60%" border="0">
            <tr>
              <td><select name="ddlDay" id="ddlDay">
                <option value="-1" >--Day--</option>
                <?php
for($i=1;$i<=31;$i++)
{
echo "<option value=$i ".isSelected($i,$day)." >$i</option>";
}
?>
              </select>              </td>
              <td><select name="ddlMonth" id="ddlMonth">
                <option value="-1">--Month--</option>
                <?php
for($i=1;$i<12;$i++)
{
echo "<option value=$i ".isSelected($i,$month)." >$i</option>";
}
?>
              </select>              </td>
              <td><select name="ddlYear" id="ddlYear">
                <option  value="-1">--Year--</option>
                <?php
 $year=date("Y");

for($i=$year-18;$i>$year-50;$i--)
{
echo "<option value=$i ".isSelected($i,$year)." >$i</option>";
}

?>
              </select>              </td>
            </tr>
          </table><span style="color:#FF0000;font-size:9px"><?php echo $err_bithday; ?></span></td>
        </tr>
        <tr>
          <td><strong>Email</strong></td>
          <td><input name="txtEmail" type="text" id="txtEmail" size="40" maxlength="100" value="<?php echo $email;?>" /></td>
        </tr>
        <tr>
          <td><strong>Telephone</strong></td>
          <td><input name="txtTelephone" type="text" id="txtTelephone" size="12" maxlength="10" value="<?php echo $telephone;?>" /></td>
        </tr>
        <tr>
          <td>&nbsp;</td>
          <td><input type="submit" name="btnSave" id="btnSave" value="Save" />
            <input type="reset" name="Reset" id="button" value="Reset" /></td>
        </tr>
        <tr>
          <td colspan="2"><div align="center"><?php echo $msg; ?>
            </div></td>
          </tr>
      </table>
        </form>    </td>
  </tr>
  <tr>
    <td colspan="2">&nbsp;</td>
  </tr>
  <tr>
    <td colspan="2">&nbsp;</td>
  </tr>
  <tr>
    <td colspan="2">&nbsp;</td>
  </tr>
</table>
</body>
</html>
<?php
}
else
{
header("Location:../login.php");
}
?>

No comments

Thank you very much for your ideas!