Advertisement
Guest User

Cannot update to database

a guest
Nov 18th, 2019
210
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
HTML 7.50 KB | None | 0 0
  1. <?php
  2. session_start();
  3. error_reporting(0);
  4. include('includes/config.php');
  5. if(strlen($_SESSION['emplogin'])==0)
  6.    {  
  7. header('location:index.php');
  8. }
  9. else{
  10. if(isset($_POST['apply']))
  11. {
  12. $empid=$_SESSION['eid'];
  13. $leavetype=$_POST['leavetype'];
  14. $fromdate=$_POST['fromdate'];  
  15. $todate=$_POST['todate'];
  16. $description=$_POST['description'];  
  17. $fname=$_POST['FirstName'];
  18. $lname=$_POST['LastName'];
  19. $status=0;
  20. $isread=0;
  21.  
  22. if($fromdate > $todate){
  23.                 $error=" ToDate should be greater than FromDate ";
  24.            }
  25. $sql="INSERT INTO tblleaves(FirstName,LastName,LeaveType,ToDate,FromDate,Description,Status,IsRead,empid) VALUES(:fname,:lname,:leavetype,:todate,:fromdate,:description,:status,:isread,:empid)";
  26.  
  27. $query = $dbh->prepare($sql);
  28. $query->bindParam(':fname',$fname,PDO::PARAM_STR);
  29. $query->bindParam(':lname',$lname,PDO::PARAM_STR);
  30. $query->bindParam(':leavetype',$leavetype,PDO::PARAM_STR);
  31. $query->bindParam(':fromdate',$fromdate,PDO::PARAM_STR);
  32. $query->bindParam(':todate',$todate,PDO::PARAM_STR);
  33. $query->bindParam(':description',$description,PDO::PARAM_STR);
  34. $query->bindParam(':status',$status,PDO::PARAM_STR);
  35. $query->bindParam(':isread',$isread,PDO::PARAM_STR);
  36. $query->bindParam(':empid',$empid,PDO::PARAM_STR);
  37. $query->execute();
  38. $lastInsertId = $dbh->lastInsertId();
  39. if($lastInsertId)
  40. {
  41. $msg="Permohonan Berjaya";
  42. }
  43. else
  44. {
  45. $error="Maaf, sila cuba sekali lagi";
  46. }
  47.  
  48. }
  49.  
  50.     ?>
  51.  
  52.  
  53. <div class="row">
  54.  
  55. <!DOCTYPE html>
  56. <html lang="en">
  57.     <head>
  58.        
  59.         <!-- Title -->
  60.         <title>Pelajar | Permohonan Keluar</title>
  61.        
  62.         <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no"/>
  63.         <meta charset="UTF-8">
  64.         <meta name="description" content="Responsive Admin Dashboard Template" />
  65.         <meta name="keywords" content="admin,dashboard" />
  66.         <meta name="author" content="Steelcoders" />
  67.        
  68.         <!-- Styles -->
  69.         <link type="text/css" rel="stylesheet" href="assets/plugins/materialize/css/materialize.min.css"/>
  70.         <link href="./assets/css/icon.css" rel="stylesheet">
  71.         <link href="assets/plugins/material-preloader/css/materialPreloader.min.css" rel="stylesheet">
  72.         <link href="assets/css/alpha.min.css" rel="stylesheet" type="text/css"/>
  73.         <link href="assets/css/custom.css" rel="stylesheet" type="text/css"/>
  74.   <style>
  75.         .errorWrap {
  76.     padding: 10px;
  77.     margin: 0 0 20px 0;
  78.     background: #fff;
  79.     border-left: 4px solid #dd3d36;
  80.     -webkit-box-shadow: 0 1px 1px 0 rgba(0,0,0,.1);
  81.     box-shadow: 0 1px 1px 0 rgba(0,0,0,.1);
  82. }
  83. .succWrap{
  84.     padding: 10px;
  85.     margin: 0 0 20px 0;
  86.     background: #fff;
  87.     border-left: 4px solid #5cb85c;
  88.     -webkit-box-shadow: 0 1px 1px 0 rgba(0,0,0,.1);
  89.     box-shadow: 0 1px 1px 0 rgba(0,0,0,.1);
  90. }
  91.         </style>
  92.  
  93.  
  94.  
  95.     </head>
  96.     <body>
  97.   <?php include('includes/header.php');?>
  98.            
  99.        <?php include('includes/sidebar.php');?>
  100.    <main class="mn-inner">
  101.                 <div class="row">
  102.                     <div class="col s12">
  103.                         <div class="page-title">Permohonan Keluar Bengkel</div>
  104.                     </div>
  105.                     <div class="col s12 m12 l8">
  106.                         <div class="card">
  107.                             <div class="card-content">
  108.                                 <form id="example-form" method="post" name="addemp">
  109.                                     <div>
  110.                                         <h3>Permohonan Keluar Bengkel</h3>
  111.                                         <section>
  112.                                             <div class="wizard-content">
  113.                                                 <div class="row">
  114.                                                     <div class="col m12">
  115.                                                         <div class="row">
  116.      <?php if($error){?><div class="errorWrap"><strong>RALAT </strong> ! <?php echo htmlentities($error); ?> </div><?php }
  117.                else if($msg){?><div class="succWrap"><strong>TAHNIAH</strong> ! <?php echo htmlentities($msg); ?> </div><?php }?>
  118.  
  119.  
  120.  <div class="input-field col  s12">
  121. <select  name="leavetype" autocomplete="off">
  122. <option value="">Sila Pilih Jenis Urusan @ Tujuan</option>
  123. <?php $sql = "SELECT  LeaveType from tblleavetype";
  124. $query = $dbh -> prepare($sql);
  125. $query->execute();
  126. $results=$query->fetchAll(PDO::FETCH_OBJ);
  127. $cnt=1;
  128. if($query->rowCount() > 0)
  129. {
  130. foreach($results as $result)
  131. {   ?>                                            
  132. <option value="<?php echo htmlentities($result->LeaveType);?>"><?php echo htmlentities($result->LeaveType);?></option>
  133. <?php }} ?>
  134. </select>
  135. </div>
  136.  
  137. <?php
  138. $eid=$_SESSION['eid'];
  139. $sql = "SELECT FirstName,LastName from tblemployees where id=:eid";
  140. $query = $dbh -> prepare($sql);
  141. $query->bindParam(':eid',$eid,PDO::PARAM_STR);
  142. $query->execute();
  143. $results=$query->fetchAll(PDO::FETCH_OBJ);
  144. $cnt=1;
  145. if($query->rowCount() > 0)
  146. {
  147. foreach($results as $result)
  148. {               ?>  
  149.                        <?php }} ?>
  150.  
  151. <div class="input-field col m6 s12">
  152. <label for="firstName"></label>
  153. <input id="firstName" name="firstName" value="<?php echo htmlentities($result->FirstName);?>"  type="text" readonly required>
  154. </div>
  155.  
  156. <div class="input-field col m6 s12">
  157. <label for="lastName"> </label>
  158. <input id="lastName" name="lastName" value="<?php echo htmlentities($result->LastName);?>" type="text" readonly autocomplete="off" required>
  159. </div>
  160.  
  161. <div class="input-field col m6 s12">
  162. <label for="fromdate">Tarikh Permohonan</label>
  163. <input placeholder="" id="mask1" name="fromdate" class="masked" type="text" data-inputmask="'alias': 'date'" required>
  164. </div>
  165. <div class="input-field col m6 s12">
  166. <label for="todate">Tarikh Pulang</label>
  167. <input placeholder="" id="mask1" name="todate" class="masked" type="text" data-inputmask="'alias': 'date'" required>
  168. </div>
  169. <div class="input-field col m12 s12">
  170. <label for="birthdate">Huraian</label>    
  171.  
  172. <textarea id="textarea1" name="description" class="materialize-textarea" length="500" required></textarea>
  173. </div>
  174. </div>
  175.       <button type="submit" name="apply" id="apply" class="waves-effect waves-light btn indigo m-b-xs">Mohon</button>                                            
  176.  
  177.                                                 </div>
  178.                                             </div>
  179.                                         </section>
  180.                                      
  181.                                    
  182.                                         </section>
  183.                                     </div>
  184.                                 </form>
  185.                             </div>
  186.                         </div>
  187.                     </div>
  188.                 </div>
  189.             </main>
  190.         </div>
  191.         <div class="left-sidebar-hover"></div>
  192.        
  193.         <!-- Javascripts -->
  194.         <script src="assets/plugins/jquery/jquery-2.2.0.min.js"></script>
  195.         <script src="assets/plugins/materialize/js/materialize.min.js"></script>
  196.         <script src="assets/plugins/material-preloader/js/materialPreloader.min.js"></script>
  197.         <script src="assets/plugins/jquery-blockui/jquery.blockui.js"></script>
  198.         <script src="assets/js/alpha.min.js"></script>
  199.         <script src="assets/js/pages/form_elements.js"></script>
  200.           <script src="assets/js/pages/form-input-mask.js"></script>
  201.                 <script src="assets/plugins/jquery-inputmask/jquery.inputmask.bundle.js"></script>
  202.     </body>
  203. </html>
  204. <?php } ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement