How to build a PHP Application: College Management System

2

The following is a sample College Management System. I have developed this for a better understanding of PHP and I have also incorporated some of the features like sending mails. You can download the source code and modify the structure according to your needs.

This will be very useful for beginners wanting to learn PHP. I am attaching all the related source codes in a single zip file.

  1. Before you start, please install WAMP or XAMPP for checking the webpages internally.
  2. Create a database called dbsmtp and create the tables required by checking the code admin2008.php and process.php.
  3. I am working on the demo for a better understanding. For now, download the files as it will benefit in understanding the Mail framework in PHP and also how the DB connectivity works.
  4. The code below provides the example of checking the data from a database.
  5. In the next post, I will post the UI details of the webpage and demonstrate the coding.

Example of DB connectivity in a webpage using functions:

__write($query) ==1 )
{
$_POST[‘sts’]= $oemail.” successfully created”;
include_once(“status.php”);
}
else
{
$_POST[‘sts’]= $oemail.” email already exist”;
include_once(“status.php”);
}
}
else
{
$_POST[‘sts’]= “some field data missing”;
include_once(“status.php”);
}

}

function userpasschk()
{
include_once(“admin/admin2008.php”);
$adb= new admindbase ();

$user=$_POST[‘user’];
$pass=$_POST[‘pass’];

if( !empty($user) && !empty($pass) )
{
if($adb->__upcheck($user,$pass) == 1 )
{
retrive();
return;
}
}

header(“Location: index.php”);
}

function compose ()
{
$attch=””;
$from=$_POST[‘from’] ;
$to=$_POST[‘to’];
$subj=$_POST[‘subj’];
$body=$_POST[‘body’];
$tfname=$_FILES[‘file’][‘tmp_name’];
//$fname=$_FILES[‘file’][‘name’];
//$ftype=$_FILES[‘file’][‘type’];

if( !empty($from) && !empty($to) && !empty($subj) && !empty($body) )
{
include_once(“admin/admin2008.php”);
$adb= new admindbase ();
if( !empty($tfname) )
$attch=setattach($tfname);

$query=sprintf(“insert into mails (source,dest,subject,attach,body) values(‘%s’,’%s’,’%s’,’%s’,’%s’)”,$from,$to,$subj,$attch,$body);
if( $adb->__write($query) ==1 )
{
$_POST[‘sts’]= “email send to “. $to;
include_once(“status.php”);
}
else
{
$_POST[‘sts’]= “email failed send to “. $to;
include_once(“status.php”);
}
}
else
{
$_POST[‘sts’]= “field missing”;
include_once(“status.php”);
}

}

function setattach($tfname)
{
if($_FILES[‘file’][‘error’][0]==UPLOAD_ERR_OK)
{
$size=filesize($tfname);
$fp=fopen($tfname,”r”);
$content=addslashes(fread($fp,$size));
fclose($fp);
return $content;
}
else
return “”;
}

function retrive()
{

include_once(“admin/admin2008.php”);
$adb= new admindbase ();
$user = $_POST[‘user’];
$query =sprintf( “select * from mails where dest=’%s'”,$user);
$rs=$adb->__read($query);
for ( $i=0; $i<count($rs); $i++)
echo $rs [$i][‘source’] . ““.$rs[$i][‘subject’] .”
“;
}
?>

Download from the following link. I will post the next update in the coming posts. I will also post a working demo of the same.

Download Link: College Management System in PHP

Get the best of Durofy in your inbox

Share.

About Author

2 Comments

  1. Pingback: [Tutorial 2] How to build a PHP Application: College Management System