File "slider.php"
Full Path: /home/krishnamexports/public_html/panel/pages/product_review/slider.php
File size: 8.47 KB
MIME-type: text/x-php; charset=us-ascii
Charset: utf-8
<?php
if(isset($_POST['add']))
{
$type = $_POST['type'];
$title = mysqli_real_escape_string($cn,$_POST['title']);
$slider = $_FILES['slider']['name'];
$link = $_POST['link'];
$slider_order = $_POST['slider_order'];
$description = mysqli_real_escape_string($cn,$_POST['description']);
$imgValidation = 1;
// get the image extension
$extension = substr($slider,strlen($slider)-4,strlen($slider));
// allowed extensions
$allowed_extensions = array(".jpg","jpeg",".png",".JPG","JPEG",".PNG");
// Validation for allowed extensions .in_array() function searches an array for a specific value.
if(!in_array($extension,$allowed_extensions))
{
$imgValidation = 0;
$_SESSION['errorMsg'] = '<div class="alert alert-danger"><strong>Danger!</strong> Upload Invalid Img Format.</div>';
}
else
{
move_uploaded_file($_FILES['slider']['tmp_name'],'../slider/'.$slider);
}
if($imgValidation==1)
{
$sqlSubject = mysqli_query ($cn, "insert into `tbl_slider` set `type`='".$type."', `title`='".$title."', `slider`='".$slider."', `link`='".$link."', `slider_order`='".$slider_order."', `description`='".$description."'");
if ($sqlSubject)
{
echo '<div class="alert alert-success"><strong>Success!</strong> Slider Added Successfully.</div>';
}
else
{
echo '<div class="alert alert-danger"><strong>Danger!</strong> Slider Not Added. Try Again.</div>';
}
}
else
{
echo $_SESSION['errorMsg'];
}
}
if(isset($_POST['edit']))
{
$id = $_POST['id'];
$type = $_POST['type'];
$title = mysqli_real_escape_string($cn,$_POST['title']);
$slider = $_FILES['slider']['name'];
$link = $_POST['link'];
$slider_order = $_POST['slider_order'];
$description = mysqli_real_escape_string($cn,$_POST['description']);
$sql = mysqli_query($cn, "select * from tbl_slider where id='$id'");
$sqlData = mysqli_fetch_array($sql);
if(!empty($slider))
{
move_uploaded_file($_FILES['slider']['tmp_name'],'../slider/'.$slider);
}
else
{
$slider = $sqlData['slider'];
}
$sqlSubject = mysqli_query ($cn,"update tbl_slider SET `type`='".$type."', `title`='".$title."', `slider`='".$slider."', `link`='".$link."', `slider_order`='".$slider_order."', `description`='".$description."' where `id`='".$id."'");
if($sqlSubject)
{
echo '<div class="alert alert-success"><strong>Success!</strong> Slider Update Successfully.</div>';
}
else
{
echo '<div class="alert alert-success"><strong>Warning!</strong> Not Updated try again.</div>';
}
}
if(isset($_GET['edit_id']))
{
$id = $_GET['edit_id'];
$sql = mysqli_query($cn, "select * from tbl_slider where id='$id'");
$sqlData = mysqli_fetch_array ($sql);
}
if(isset($_GET['delete_id']))
{
$id = $_GET['delete_id'];
$sql = mysqli_query($cn, "delete from tbl_slider where id='$id'");
if($sql)
{
echo '<div class="alert alert-success"><strong>Success!</strong> Slider Deleted Successfully.</div>';
}
else
{
echo "error: " . $sql . "<br>" . mysqli_error($conn);
}
}
?>
<div class="card">
<div class="card-body">
<h4 class="card-title">Slider</h4>
<form class="forms-sample" method="post" enctype="multipart/form-data">
<div class="row">
<div class="col-md-4">
<div class="form-group">
<label for="exampleInputCity1">Slider Effect Type <span style="color:#F00;">*</span></label>
<input type="hidden" name="id" value="<?php if(isset($_GET['edit_id'])) {echo $sqlData['id'];}?>">
<select class="form-control" name="type" required>
<option>Select Type</option>
<option value="1" <?php if(isset($_GET['edit_id'])){ if($sqlData['type']==1){ echo "selected";}}?>>Left Align Content With Bounce</option>
<option value="2" <?php if(isset($_GET['edit_id'])){ if($sqlData['type']==2){ echo "selected";}}?>>Right Align Content With Bounce</option>
<option value="3" <?php if(isset($_GET['edit_id'])){ if($sqlData['type']==3){ echo "selected";}}?>>Left Align Content With Slideup</option>
<option value="4" <?php if(isset($_GET['edit_id'])){ if($sqlData['type']==4){ echo "selected";}}?>>Right Align Content With Slideup</option>
</select>
</div>
</div>
<div class="col-md-8">
<div class="form-group">
<label for="exampleInputCity1">Slider Title</label>
<input type="text" class="form-control" name="title" value="<?php if(isset($_GET['edit_id'])) {echo $sqlData['title'];}?>" id="exampleInputCity1"placeholder="Slider Title">
</div>
</div>
<div class="col-md-4">
<label for="exampleInputCity1">Upload Slider Image <span style="color:#F00;">*</span></label>
<input type="file" name="slider" id="fileToUpload" <?php if(isset($_GET['edit_id'])){}else{?> required <?php }?>>
<?php if(isset($_GET['edit_id'])) {?><br />
<img src="../slider/<?php echo $sqlData['slider'];?>" width="100%">
<?php }?>
<p style="color:red; ">Size must 1920X670</p>
</div>
<div class="col-md-4">
<div class="form-group">
<label for="exampleInputCity1">Slider Link</label>
<input type="text" class="form-control" name="link" value="<?php if(isset($_GET['edit_id'])) {echo $sqlData['link'];}?>" id="exampleInputCity1"placeholder="Slider Link">
</div>
</div>
<div class="col-md-4">
<div class="form-group">
<label for="exampleInputCity1">Slider Order <span style="color:#F00;">*</span></label>
<input type="text" class="form-control" name="slider_order" id="exampleInputCity1" placeholder="Slider Order" value="<?php if(isset($_GET['edit_id'])) {echo $sqlData['slider_order'];}?>" required/>
</div>
</div>
<div class="col-md-12">
<div class="form-group">
<label for="exampleInputCity1">Slider Description (150 Words)</label>
<textarea class="form-control" name="description" placeholder="Slider Description"><?php if(isset($_GET['edit_id'])) {echo $sqlData['description'];}?></textarea>
</div>
</div>
</div>
<button type="submit" class="btn btn-success mr-2" name="<?php if(isset($_GET['edit_id'])) {echo "edit";}else{ echo "add";}?>">Submit</button>
</form>
</div>
</div>
<br/>
<style>
.table td img, .table th img {
border-radius:0;
}
.table td img, .table th img {
width:150px;
height:75px;
}
</style>
<div class="card">
<div class="card-body">
<h4 class="card-title">Slider List</h4>
<div class="table-responsive">
<table class="table table-striped">
<thead>
<tr>
<th>Sr. No.</th>
<th>Image</th>
<th>Title</th>
<th>Link</th>
<th>Order</th>
<th>Action</th>
</tr>
</thead>
<tbody>
<?php
$i = 1;
$sqlEmployee = mysqli_query($cn, "select * from `tbl_slider`");
while($sqlEmployeeData = mysqli_fetch_array($sqlEmployee)){
?>
<tr>
<td><?php echo $i++;?></td>
<td><img src="../slider/<?php echo $sqlEmployeeData['slider'];?>" height="150" width="200"></td>
<td><?php echo $sqlEmployeeData['title'];?></td>
<td><?php echo $sqlEmployeeData['link'];?></td>
<td><?php echo $sqlEmployeeData['slider_order'];?></td>
<td><a href="home.php?pages=slider&edit_id=<?php echo $sqlEmployeeData['id'];?>">Edit</a> | <a href="home.php?pages=slider&delete_id=<?php echo $sqlEmployeeData['id'];?>" onclick="return deleteConfirm();">Delete</a></td>
</tr>
<?php } ?>
</tbody>
</table>
</div>
</div>
</div>