- Admin Login
- Edit / delete Student
- Edit /delete Staff
- Register Student or Staff
At the beginning of the coursework, I have not intended to create admin as well as update their details. I was assuming that admin will be create by staff record system however for the sake of demonstration I thing it is really good idea to have an admin.
however I have not create any database table for an admin. so I create one admin inside the php script for the login admin page.which mean that the username and password that I specifed is "admin".
<?php
if(isset($_POST['register']))
{
// checked if the value is valid, than go to admin page
$username = trim($_POST['username']);
$password = trim($_POST['password']);
//$hashed_password = sha1($password);
if(strlen($username) && strlen($password))
{
//noted here: not checked from database
if($username == 'admin' && $password = 'admin' ){header("Location: adminPage.php");}
}
//if not valid then so an error message
else
{
$msg = "Could not register user";
}
}
?>
When admin had successfuly login in then it will go to admin page, shown below
Edit Student
Edit student is similar to Edit staff, I will describe one of them on how the system work
as we can see from the picture above, the edit student link has been pressed. The Material area has been changed by adminPage_studentlist.php which listed all student including delete button on the right.
one of the student need to be selected in order to be edited otherwise error message will be displayed.
This is adminPage_studentlist.php the code:
<?php require_once('dmwp_connect.php');
//the action inside form tag will be send any vaule from this form to studentList.php
?>
<div align="center">
<form id="userform" name="userform" method="post" action="studentList.php">
<table width='460' border='1' cellpadding="1" cellspacing="1">
<tr align="center" >
<td> </td>
<td><strong> Student Id</strong></td>
<td><strong> User Name</strong></td>
<td><strong> First Name</strong></td>
<td><strong> Last Name</strong></td>
<td> </td>
</tr>
<?php
if(!mysql_select_db($dbname, $con))
{
echo"db failed!";
};
//select data from units table return material which specify to particular staff. $staffNo indicate the
//uniq id for particular staff which has been sent by login page
$result = mysql_query("SELECT * FROM `student` ");
while($row = mysql_fetch_array($result))
{
//print the list of all student from database as a table
echo "<tr>
<td align='center'><input type='radio' name='editStudent' id='user_id' value=$row[std_id]> </td>
<td> $row[std_id]</td>
<td> $row[std_name]</td>
<td> $row[std_first]</td>
<td> $row[std_last]</td>
<td> <a href='deleteStaffOrStudent.php?user_id=$row[std_id]&stafforstudent=student'><img src='images/delete.png' /></td>
</tr>";
}
if ( !mysql_close($con)){echo "close failure";}
?>
<tr align="center" >
<td colspan="56"><input type="submit" id = "register" name="register" value="Select Student"/></td>
</tr>
</table>
</form>
</div>
StudentList.php
<?php require_once('dmwp_connect.php');
$user_id = $_POST['editStudent'];
if($user_id == null)
{echo "<p align = 'center'>Error, Please Select one of student</p>";
}
else{
?>
<div align="center">
<form id="userform" name="userform" method="post" action="updateStudent.php" onsubmit="return chekForm()">
<table width="402" border="0">
<tr>
<td height="36" colspan="2"><div align="center"><strong>Update StudentDetails </strong></div></td>
</tr>
<tr>
<td width="131"><span class="style5">Username</span></td>
<td width="261"><input type="hidden" name="studentID" id="studentID" value="<?php echo $_POST['editStudent']; ?>" />
<?php
if(!mysql_select_db($dbname, $con))
{
echo"db failed!";
};
$result = mysql_query("SELECT std_name , std_email, std_first, std_last, phone_no FROM student Where std_id=$user_id ");
while($row = mysql_fetch_array($result))
{
//
echo $row[std_name];
?> </td>
</tr>
<tr>
<td width="131">First name</td>
<td><span class="style6"><input name="firstname" type="text" id="firstname" value="<?php echo $row[std_first];?>"/> </span></td>
</tr>
<tr>
<td width="131">Last name</td>
<td><span class="style6"><input name="lastname" type="text" id="lastname" value="<?php echo $row[std_last];?>" /> </span></td>
</tr><tr>
<td width="131">Email</td>
<td><span class="style6"><input name="email" type="text" id="email" size="30" value="<?php echo $row[std_email];?>"/> </span></td>
</tr><tr>
<td width="131">Phone number</td>
<td><span class="style6"><input name="phoneno" type="text" id="phoneno" value="<?php echo $row[phone_no];};?>"/> </span></td>
</tr>
<td> </td>
<td><div>
<input type="submit" id = "register" name="register" value="update"/>
</div></td>
</tr>
</table>
</form>
<?php } ?>
</div>
No comments:
Post a Comment