Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- try{
- include_once "inc/db.inc.php" ;
- include "inc/sessions.inc.php";
- // Inserting into Database :
- date_default_timezone_set('Asia/Amman');
- $Current_time = time();
- $DateTime = strftime("%d-%m-%Y/%H:%M",$Current_time);
- if($_SERVER['REQUEST_METHOD'] === 'POST'){
- if(isset($_POST['btn'])){
- if(!empty($_POST['name'])){
- $admin = "Anonymous" ; //Default Admin
- $Query = "INSERT INTO categories(datetime,creatorname,name)
- VALUES(?,?,?)";
- $Statement = $Connection->prepare($Query);
- $Statement-> bindValue(1,$DateTime);
- $Statement-> bindValue(2,$admin);
- $Statement-> bindValue(3,$_POST['name']);
- $Statement-> execute();
- $_SESSION['SuccessMessage'] = "Successfully Added One New Category !" ;
- } //if !empty(name)
- else {
- $_SESSION['ErrorMessage'] = "Please Fill The Feilds Correctly !" ;
- }
- } //if isset(btn)
- else {
- $_SESSION['ErrorMessage'] = "Sorry Something Went Wrong";
- }
- }
- //Fetch out from the DB
- $Fetch = "SELECT * FROM categories" ;
- $Srno = 0;
- $Statement2 = $Connection->prepare($Fetch);
- $Statement2-> bindColumn('datetime',$DateTimeE);
- $Statement2-> bindColumn('creatorname',$adminE);
- //
- //
- //
- //
- //
- //
- // Getting Errors
- $errorInfo = $Connection-> errorInfo();
- if(isset($errorInfo[2])){
- $error = $errorInfo[2];
- }
- }
- catch (Exception $e) {
- $error = $e-> getmessage();
- }
- ?>
- <!DOCTYPE html>
- <html>
- <head>
- <meta charset="utf-8">
- <meta name="viewport" content="width=device-width, initial-scale=1">
- <meta name="description" content="Your Description">
- <link rel="stylesheet" href="css/bootstrap.min.css">
- <link rel="stylesheet" href="css/pub.css">
- <script src="js/jquery-3.3.1.min.js"></script>
- <script src="js/bootstrap.min.js"></script>
- <title>My Blog</title>
- </head>
- <body>
- <?php
- if(isset($error)) {
- echo "<div class="alert alert-danger">".
- $error
- ."</div>" ;
- }
- else {
- ?>
- <div class="container-fluid">
- <div class="row">
- <div class="col-sm-2">
- <ul class="nav nav-pills nav-stacked" id="sideNav">
- <br>
- <li><a href="dashboard.php">Dashboard</a></li>
- <li><a href="users.php"> Users</a></li>
- <li><a href="compose.php">Compose</a></li>
- <li class="active"><a href="categories.php">Categories</a></li>
- <li><a href="comments.php">Comments</a></li>
- <li><a href="index.php">Live Blog</a></li>
- <li><a href="logout.php">Logout</a></li>
- </ul>
- </div> <!-- col-sm-2 -->
- <div class="col-sm-10">
- <h1>Categories :</h1>
- <form method="post" action="categories.php">
- <div class="form-group">
- <div> <?php echo Message() ; echo SuccessMessage() ;?> </div>
- <label for="name">Create New Category :</label>
- <input type="text" id="name" class="form-control" placeholder="Category name" name="name"> <br>
- <input id="btn" type="submit" name="btn" value="submit" class="btn btn-success btn-block">
- </div>
- </form>
- <hr>
- <!-- Fetching Out Some Data From The Database/ -->
- <table class="table table-responsive table-stripped table-hover">
- <tr>
- <th>Sr.no</th>
- <th>Created at</th>
- <th>Creator</th>
- <th>Name</th>
- </tr>
- <?php $Statement2->fetch(PDO::FETCH_BOUND);?>
- <?php while($Statement2->fetch(PDO::FETCH_BOUND)){?>
- <tr>
- <td><?php echo $DateTimeE;?></td>
- <td><?php echo $adminE;?></td>
- </tr>
- <?php }?>
- </table>
- </div> <!-- col-sm-10 -->
- </div> <!-- row -->
- </div> <!-- Container-fluid -->
- <?php }?>
- </body>
- </html>
Add Comment
Please, Sign In to add comment