Guest User

Untitled

a guest
Mar 17th, 2018
94
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.23 KB | None | 0 0
  1. <?php
  2.  
  3. try{
  4. include_once "inc/db.inc.php" ;
  5. include "inc/sessions.inc.php";
  6. // Inserting into Database :
  7.  
  8. date_default_timezone_set('Asia/Amman');
  9. $Current_time = time();
  10. $DateTime = strftime("%d-%m-%Y/%H:%M",$Current_time);
  11.  
  12. if($_SERVER['REQUEST_METHOD'] === 'POST'){
  13. if(isset($_POST['btn'])){
  14. if(!empty($_POST['name'])){
  15. $admin = "Anonymous" ; //Default Admin
  16.  
  17.  
  18. $Query = "INSERT INTO categories(datetime,creatorname,name)
  19. VALUES(?,?,?)";
  20.  
  21.  
  22. $Statement = $Connection->prepare($Query);
  23. $Statement-> bindValue(1,$DateTime);
  24. $Statement-> bindValue(2,$admin);
  25. $Statement-> bindValue(3,$_POST['name']);
  26. $Statement-> execute();
  27.  
  28.  
  29.  
  30.  
  31. $_SESSION['SuccessMessage'] = "Successfully Added One New Category !" ;
  32.  
  33.  
  34. } //if !empty(name)
  35. else {
  36. $_SESSION['ErrorMessage'] = "Please Fill The Feilds Correctly !" ;
  37.  
  38. }
  39. } //if isset(btn)
  40. else {
  41. $_SESSION['ErrorMessage'] = "Sorry Something Went Wrong";
  42. }
  43.  
  44. }
  45.  
  46.  
  47. //Fetch out from the DB
  48.  
  49. $Fetch = "SELECT * FROM categories" ;
  50. $Srno = 0;
  51.  
  52. $Statement2 = $Connection->prepare($Fetch);
  53. $Statement2-> bindColumn('datetime',$DateTimeE);
  54. $Statement2-> bindColumn('creatorname',$adminE);
  55.  
  56.  
  57. //
  58. //
  59. //
  60. //
  61. //
  62. //
  63. // Getting Errors
  64.  
  65.  
  66.  
  67.  
  68.  
  69. $errorInfo = $Connection-> errorInfo();
  70.  
  71. if(isset($errorInfo[2])){
  72. $error = $errorInfo[2];
  73. }
  74.  
  75. }
  76.  
  77. catch (Exception $e) {
  78. $error = $e-> getmessage();
  79.  
  80. }
  81. ?>
  82.  
  83.  
  84.  
  85. <!DOCTYPE html>
  86. <html>
  87. <head>
  88. <meta charset="utf-8">
  89. <meta name="viewport" content="width=device-width, initial-scale=1">
  90. <meta name="description" content="Your Description">
  91.  
  92.  
  93. <link rel="stylesheet" href="css/bootstrap.min.css">
  94. <link rel="stylesheet" href="css/pub.css">
  95. <script src="js/jquery-3.3.1.min.js"></script>
  96. <script src="js/bootstrap.min.js"></script>
  97.  
  98.  
  99.  
  100. <title>My Blog</title>
  101.  
  102.  
  103.  
  104. </head>
  105.  
  106.  
  107. <body>
  108.  
  109.  
  110. <?php
  111. if(isset($error)) {
  112. echo "<div class="alert alert-danger">".
  113. $error
  114. ."</div>" ;
  115. }
  116. else {
  117. ?>
  118.  
  119.  
  120.  
  121.  
  122.  
  123. <div class="container-fluid">
  124. <div class="row">
  125. <div class="col-sm-2">
  126. <ul class="nav nav-pills nav-stacked" id="sideNav">
  127. <br>
  128. <li><a href="dashboard.php">Dashboard</a></li>
  129. <li><a href="users.php"> Users</a></li>
  130. <li><a href="compose.php">Compose</a></li>
  131. <li class="active"><a href="categories.php">Categories</a></li>
  132. <li><a href="comments.php">Comments</a></li>
  133. <li><a href="index.php">Live Blog</a></li>
  134. <li><a href="logout.php">Logout</a></li>
  135. </ul>
  136.  
  137.  
  138. </div> <!-- col-sm-2 -->
  139.  
  140.  
  141.  
  142.  
  143.  
  144.  
  145. <div class="col-sm-10">
  146. <h1>Categories :</h1>
  147.  
  148.  
  149. <form method="post" action="categories.php">
  150. <div class="form-group">
  151. <div> <?php echo Message() ; echo SuccessMessage() ;?> </div>
  152. <label for="name">Create New Category :</label>
  153. <input type="text" id="name" class="form-control" placeholder="Category name" name="name"> <br>
  154. <input id="btn" type="submit" name="btn" value="submit" class="btn btn-success btn-block">
  155. </div>
  156. </form>
  157.  
  158.  
  159.  
  160. <hr>
  161.  
  162.  
  163.  
  164.  
  165.  
  166. <!-- Fetching Out Some Data From The Database/ -->
  167.  
  168.  
  169. <table class="table table-responsive table-stripped table-hover">
  170.  
  171.  
  172. <tr>
  173. <th>Sr.no</th>
  174. <th>Created at</th>
  175. <th>Creator</th>
  176. <th>Name</th>
  177. </tr>
  178. <?php $Statement2->fetch(PDO::FETCH_BOUND);?>
  179. <?php while($Statement2->fetch(PDO::FETCH_BOUND)){?>
  180. <tr>
  181. <td><?php echo $DateTimeE;?></td>
  182. <td><?php echo $adminE;?></td>
  183.  
  184. </tr>
  185.  
  186.  
  187. <?php }?>
  188. </table>
  189.  
  190.  
  191.  
  192.  
  193. </div> <!-- col-sm-10 -->
  194.  
  195. </div> <!-- row -->
  196. </div> <!-- Container-fluid -->
  197. <?php }?>
  198. </body>
  199. </html>
Add Comment
Please, Sign In to add comment