Jump to content

Approve or reject employee leave by admin panel


renzoandredg

Recommended Posts

Hey guys, I have this page where an admin can approve/reject employee leave requests. I've attached the image file.

 

post-206906-0-03888100-1516297256_thumb.png

 

Anyway as you can see, I'm trying to get the approve/reject to show up below status and that's the result I am getting. Am I doing something wrong or am I lacking something?

 

Here's my code:

 <?php
 if(isset($_POST['approved']))
 {
  echo "Approved";
  $status=$_POST['status'];
}
if(isset($_POST['rejected']))
{
echo "Rejected";
$status=$_POST['status'];
}
?>
	
    <!-- Begin page content -->
    <div class="container">
      <div class="page-header">

<h3>
	Employee Leaves
</h3>
			<div class="table-responsive">
				<table class="table">
					<tr>
						<th>Employee Name</th>
						<th>Phone</th>
						<th>Email</th>
						<th>From</th>
						<th>To</th>
						<th>Reason</th>
						<th>Status</th>
						<th>---</th>
					</tr>
				<?php
					include ('database.php');
					$result = $database->prepare ("SELECT * FROM leaves order by id DESC");
					$result ->execute();
					for ($count=0; $row_message = $result ->fetch(); $count++){
				?>
					<tr>
						<td><?php echo $row_message['full_name']; ?></td>
						<td><?php echo $row_message['phone']; ?></td>
						<td><?php echo $row_message['email']; ?></td>
						<td><?php echo $row_message['fromdate']; ?></td>
						<td><?php echo $row_message['todate']; ?></td>
						<td><?php echo $row_message['reason']; ?></td>
						<td><?php echo $row_message['status']; ?></td>
						<td>
						<form method="post" action=""><button type="submit" name="approved">Approve</button></form>
						&nbsp
						<form method="post" action=""><button type="submit" name="rejected">Reject</button></form>
						</td>
					</tr>
					<?php	}	?>
				</table>
				
				<a href="home"><button type="button" class="btn btn-primary"><i class="glyphicon glyphicon-arrow-left"></i> Back</button></a>
				
			</div>
  </div>
Link to comment
Share on other sites

I dont' see where you are outputting the result near anything. You are just doing an echo.

 

What do you really want to do? Output all the data once again with the result showing in a certain place? Then output all of the data.

 

Look up the heredocs construct in the manual. Makes it a whole lot easier to output the kind of stuff you are doing.

 

$code=heredocs
<tr>
<td>$row_message['full_name']</td>
<td>$row_message['phone']</td>
<td>$row_message['email']</td>
<td>$row_message['fromdate']</td>
<td>$row_message['todate']</td>
<td>$row_message['reason']</td>
<td>$row_message['status']</td>
<td>
<form method="post" action="">
<button type="submit" name="approved">Approve</button>
</form>
&nbsp
<form method="post" action="">
<button type="submit" name="rejected">Reject</button>
</form>
</td>
</tr>
heredocs;
echo $code;
PS - I suggest using a true 'submit' button (an <input> tag, not a <button> tag).
Link to comment
Share on other sites

Hi,

 

May I ask what would be most efficient & simplest possible way to handle errors / exceptions in a code like above : 

 
For e.g. say i had a function like checkMail($row_message['email']l ) which returns a false because it's a malformed email and more such functions to check for say numeric values etc.
 
So what would be the simplest way to handle these errors.
 
-- Hope I am not breaking any rules here by asking another, albeit related question here.
 
Thanks.
Link to comment
Share on other sites

Hi ginerjm ! Thanks for the response. 

 

Testing each function call within it's own if block seems to be very cumbersome and long winded. I was actually wondering if there was something simpler, a better method to check and handle these errors. 

 

Thank you.

Link to comment
Share on other sites

It depends on the function and what it is doing. Sometimes you may have to check for things INSIDE the function and abort the whole process. Other times you can just return false and let the main block of code decide what needs to be done.

 

Handling errors is a broad subject and depends on the the app and where you are in its processes. The programmer decides that. For example - if you have a module that handles your db connection you may call a function in that module to connect and if it fails you probably want to just abort the whole app since failing to get to the db kinda ends the whole activity that the user wants to do, no? In other cases, such as when you call a function to do a lookup for something and the lookup fails you may just return a false value and let the caller decide what to do.

 

Yes - error handling is a large part of writing a GOOD appl. Failure to do produces a weak app or a bad user experience. A good programmer handles this.

 

"no one ever said this was going to be easy"

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.