Code:
<?php
mysql_connect('localhost','root',"") or die('cannot connect');
mysql_select_db('mathematics')or die('cannot connect to db');
function loginForm()
{
echo '
<div id="container2">
<div id="nav-right">
<div id="sideright-top"><p class="class2">Log In</p></div>
<div id="sideright-bg">
<form id="form1" name="form1" method="post" action="verify.php?invalid=<?php echo "Invalid Username or Password!"; ?>">
<table width="232" border="0">
<tr>
<td width="72"><p>Username</p></td>
<td width="150"><input name="username" type="text" id="username" /></td>
</tr>
<tr>
<td><p >Password</p></td>
<td><input name="password" type="text" id="password" /></td>
</tr>
<tr>
<td>
</td>
</tr>
<tr>
<td><p >Register</p></td>
<td><input type="submit" name="Submit" value="Login" /></td>
</tr>
</table>
</form>
</div>
<div id="sideright-buttom"></div>';
}
function userInfo($employeeid)
{
$query = "select username' from login where employeeid = '$employeeid'";
$getName = mysql_query($query);
$rowName = mysql_fetch_array($getName);
$name = $rowName['username'];
echo '
<div id="container2">
<div id="nav-right">
<div id="sideright-top"><p class="class2">Welcome, '.$name. '</p></div>
<div id="sideright-bg">
</div>
<div id="sideright-buttom"></div>';
}
function login_lib()
{
if($_POST['login'])
{
$username=$_POST['username'];
$password=$_POST['password'];
//check user if existing
$query = "select *
from login
where
username = '$username'
and password = '$password'
and type !=1 ";
$checkUser = mysql_query($query);
if(mysql_num_rows($checkUser)!=1)
{
$error = true;
$errMsg ='Error trying to validate user!';
}
elseif(mysql_num_rows($checkUser)==1)
{
$row = mysql_fetch_array($checkUser);
$userLevel = $row['type'];
$employeeid=$row['employeeid'];
if($userLevel ==2)
{
$_SESSION['loginSuccess'] = 'success';
$_SESSION['userLevel'] =2;
$_SESSION['employeeid'] = $employeeid;
header("location:index.php");
}
else
{
header("location:/faculty/index.php");
$_SESSION['loginSuccess'] = 'success';
$_SESSION['userLevel'] =3;
$_SESSION['userid'] = $employeeid;
header("location:index.php");
}
}
else
{
header("location:/mathdept");
}
}
return $error;
}
?>
Code:
<?php
session_start(); ?>
<?php
// Connect to the database
$cnx = mysql_connect("localhost", "root", "");
if (!$cnx) {
die("Unable to connect to database!");
}
// Select your database
mysql_select_db("mathematics", $cnx);
// Get data from the database
$query = mysql_query("SELECT data FROM homepage WHERE id = 1");
$data = mysql_fetch_array($query);
?>
<?php
include("dbconnect/dbconnect.php");
$error=login_lib();
include("includes/header.php");
?>
<div id="buttons"><ul id="navigation-1">
<li><a href="index.php" title="Homepage">Home</a></li>
<li><a href="aboutmath.php" title="About Math">About Math</a>
<ul class="navigation-2">
<li><a href="news.php" title="News and Events">News and Events</a></li>
<li><a href="course_offered.php" title="BS Math">Course Offered</a></li>
<li><a href="faculty.php" title="Faculty Members">Faculty Members</a></li>
<li><a href="alumni.php" title="Alumni">Alumni</a></li>
<li><a href="subjects.php" title="Subjects">Subjects</a></li>
</ul>
</li>
<li><a href="#" title="Forum">Forum</a></li>
<li><a href="downloads.php" title="Downloads">Downloads</a>
</li>
<li><a href="gallery.php" title="Gallery">Gallery</a>
<ul class="navigation-2">
<li><a href="#" title="Photos">Photos</a></li>
<li><a href="#" title="Videos">Videos</a></li>
</ul>
</li>
<li><a href="sitemap.php" title="Sitemap">Sitemap</a>
</ul></div>
<?php if($error==true){
error();
}
?>
<?php if(isset($_SESSION['loginSuccess']))
{
userInfo($_SESSION['employeeid']);
}
else
{
loginForm();
}
?>
<?php
include("includes/announcements.php"); ?>
<div id="sideleft-top"><p class="class1">Welcome to Mathematics Department</p></div>
<div id="sideleft-bg">
<?php echo $data['data']; ?>
</div>
<div id="sideleft-buttom"></div>
</div>
<?php
include("includes/footer.php");
?>