D7net
Home
Console
Upload
information
Create File
Create Folder
About
Tools
:
/
home
/
diafrica
/
spre.dominicaninstitute.edu.ng
/
Filename :
addsliders.php
back
Copy
<?php session_start(); include 'inc/config.php'; if (!isset($_SESSION['manager'])) { header('location: ./admin-auth'); exit(); } $page_title; $page_title = ucfirst(basename(__FILE__, '.php')); if ($page_title === 'index') { $page_title = 'Home'; } $page_title = "Administator's Dashboard"; include 'sections/pages-header.php'; $message = ''; function test_input($data) { $data = trim($data); $data = stripslashes($data); $data = htmlspecialchars($data); return $data; } if (isset($_GET['slider_id'])) { $sn = $_GET['slider_id']; $sql = "DELETE FROM homepage_sliders WHERE id='$sn'"; if (mysqli_query($con, $sql)) { $message = 'Carousel deleted successfully!'; $_GET['slider_id'] = ''; } else { $message = 'Error deleting record: ' . mysqli_error($con); } } ?> <div class="container" style="margin-top:50px"> <div> <a href="./mod-auth"><h2>Back to Admin Dashboard</h2></a> </div> <hr> <div> <h1>Add Carousel</h1> <?php if ( $_SERVER['REQUEST_METHOD'] == 'POST' && isset($_POST['add_slider']) ) { $heading = $caption = $button_text = $slider = ''; $heading = test_input($_POST['heading']); $caption = test_input($_POST['caption']); $button_text = test_input($_POST['button_text']); $file_name = $_FILES['slider']['name']; $file_path = 'uploads/sliders/' . $file_name; move_uploaded_file($_FILES['slider']['tmp_name'], $file_path); $feedback = "INSERT INTO homepage_sliders (slider_heading_text, slider_content_text, slider_button, slider_image) VALUES ('$heading','$caption','$button_text','$file_name')"; $run = mysqli_query($con, $feedback); if ($feedback) { echo "<div class='alert alert-success alert-dismissible' role='alert'> Picture Added Successfully! </div>"; } else { echo "<div class='alert alert-danger alert-dismissible' role='alert'> An error occured, please try again! </div>"; } } ?> <br> <form action="<?php echo htmlspecialchars( $_SERVER['PHP_SELF'] ); ?>" method="post" enctype="multipart/form-data"> <div class="row clearfix"> <div class="col-md-6 col-sm-6 col-xs-12"> <div class="form-group"> <input type="text" name="heading" class="form-control" placeholder="Slider Heading" required> </div> <div class="form-group"> <textarea name="caption" class="form-control textarea" placeholder="Slider Caption...." required></textarea> </div> <!--<div class="form-group">--> <!-- <input type="text" name="button_text" class="form-control" placeholder="Button text" required>--> <!--</div>--> <div class="form-group"> <input type="file" name="slider" class="form-control" size="60" required> </div> <div class="form-group"> <input type="submit" name="add_slider" value="Add Slider" class="thm-btn thm-color width-100"/> </div> </div> </div> </form> </div> <hr> <div> <h1>Existing Carousel</h1> <?php if (!empty($message)): ?> <div class='alert alert-danger alert-dismissible fade show'> <?= $message ?> </div> <?php endif; ?> <?php include_once './inc/config.php'; $serial = 0; $sql = 'SELECT * FROM homepage_sliders'; $result = mysqli_query($con, $sql); ?> <table id="example" class="display" style="width:100%"> <thead> <tr> <th>S/N</th> <th>Images</th> <th>Heading Text</th> <th>Content Text</th> <th>Button Text</th> <th>Action</th> </tr> </thead> <tbody> <?php if (mysqli_num_rows($result) > 0) { // output data of each row while ($row = mysqli_fetch_assoc($result)) { ?> <tr> <td><?= ++$serial ?></td> <td><img scr="./uploads/sliders/<?= $row[ 'slider_image' ] ?>" alt=""/> </td> <td><?= $row['slider_heading_text'] ?></td> <td><?= $row['slider_content_text'] ?></td> <td><?= $row['slider_button'] ?></td> <td><a href="addsliders.php?slider_id=<?= $row[ 'id' ] ?>" class="btn btn-danger">Delete</a></td> </tr> <?php } } else { //echo '0 results'; } ?> </tbody> </table> </div> </div> </div> <?php include_once 'sections/footer.php'; ?>