renzoandredg Posted January 18, 2018 Share Posted January 18, 2018 Hey guys, I have this page where an admin can approve/reject employee leave requests. I've attached the image file. 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>   <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> Quote Link to comment Share on other sites More sharing options...
ginerjm Posted January 18, 2018 Share Posted January 18, 2018 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>   <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). 1 Quote Link to comment Share on other sites More sharing options...
ajoo Posted January 20, 2018 Share Posted January 20, 2018 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. Quote Link to comment Share on other sites More sharing options...
ginerjm Posted January 20, 2018 Share Posted January 20, 2018 You are but as long as you are here: One simply tests the result of the function call and does what one wants to handle it. Basic programmer skill. Quote Link to comment Share on other sites More sharing options...
ajoo Posted January 20, 2018 Share Posted January 20, 2018 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. Quote Link to comment Share on other sites More sharing options...
ginerjm Posted January 20, 2018 Share Posted January 20, 2018 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" 1 Quote Link to comment Share on other sites More sharing options...
ajoo Posted January 20, 2018 Share Posted January 20, 2018 , thank you. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.