JezK
Edit File: editCategory.php
<?php include("header.php"); if (isset($_REQUEST['cid'])) { /*if(!isset($_REQUEST['cid'])) { echo "<script>window.location='categoriesManagement.php';</script>"; } */ $id = $videocon->encrypt_decrypt('decrypt', $_GET['cid']); $catData = $videocon->categories($id); if (count($catData) <= 0) { echo "<script>alert('Invalid details');window.location='categoriesManagement.php';</script>"; } } if (isset($_POST['action']) && $_POST['action'] == "editcategory") { $catUpdate = $videocon->updateCategory($_POST, $_FILES); if ($catUpdate) { echo "<script>alert('Category details updated successfully');window.location='categoriesManagement.php'</script>"; } else { echo "<script>alert('Category details updation was failed');window.location='categoriesManagement.php'</script>"; } } if (isset($_POST['action']) && $_POST['action'] == "addcategory") { $catUpdate = $videocon->addCategory($_POST, $_FILES); if ($catUpdate) { echo "<script>alert('Category details added successfully');window.location='categoriesManagement.php'</script>"; } else { echo "<script>alert('Category details adding was failed');window.location='categoriesManagement.php'</script>"; } } ?> <style> div.dataTables_wrapper div.dataTables_filter { position: absolute; top: 154px; } .page { height: 100% !important; } </style> <section class="section-padding px-4 h-100"> <div class="container bg-white h-100"> <div class="row pull-right p-4"> <button type=button class="btn btn-sm btn-primary w-20"><a href="categoriesManagement.php">Back</a></button> </div> <div class="row"> <div class="col-12 col-sm-12 my-3 "> <form action="" method="POST" class="container" enctype="multipart/form-data"> <div class="row justify-content-center"> <div class="col-12 col-sm-12 col-md-3"> <?php $catimage = 'img/dummybusinesspic.png'; if (isset($_REQUEST['cid'])) { if ($catData['0']['image'] != '' && file_exists('uploads/' . $catData['0']['image'])) { $catimage = 'uploads/' . $catData['0']['image']; } } ?> <label for="catimage" class="form-group d-block"> <div class="bg-Orange d-flex justify-content-center align-items-center img-thumbnail" style="width:250px; height:250px;background: #e8f2f4;"> <img src="<?php echo $catimage; ?>" id="actualImg" style="cursor:pointer;" class="w-100 h-100" /> </div> </label> <input type="file" id="catimage" name="catimage" class="d-none" accept="image/jpg,image/jpeg,image/png," onchange="readURL(this);" capture /> </div> </div> <div class="row justify-content-center"> <div class="col-12 col-sm-12 col-md-12 col-lg-5"> <div class=""> <?php if (isset($_REQUEST['cid'])) { ?> <div class="form-group "> <label for="catname" class="fieldName">Name</label> <input type="text" class="form-control formField-control" name="catname" id="catname" value="<?php if ($catData['0']['name'] != '') { echo $catData['0']['name']; } ?>"> </div> <input type="hidden" name="action" id="action" value="editcategory"> <input type="hidden" name="catid" id="catid" value="<?php echo $catData['0']['id']; ?>"> <input type="hidden" name="oldcatimage" id="oldcatimage" value="<?php echo $catData['0']['image']; ?>"> <?php } else { ?> <div class="form-group "> <label for="catname" class="fieldName">Name</label> <input type="text" class="form-control formField-control" name="catname" id="catname" value="<?php if (isset($_POST['catname']) && $_POST['catname'] != '') { echo $_POST['catname']; } ?>"> </div> <input type="hidden" name="action" id="action" value="addcategory"> <?php } ?> </div> </div> </div> <div class="row justify-content-center"> <div class="col-12 col-sm-12 col-md-12 col-lg-5"> <div class="form-group mt-2 mb-2"> <button class="btn basic-btn-color w-100" onclick="return categoryValidations();"><?php if (isset($_REQUEST['cid'])) { echo "Update"; } else { echo "Add"; }; ?></button> </div> </div> </div> <!-- </div> </div> --> </form> </div> </div> </div> </section> <?php include("footer.php"); ?> <script type="text/javascript"> function showPassword(inputValue) { if (inputValue === 1) { var currentPasswordType = document.getElementById('currentPassword'); if (currentPasswordType.type === 'password') { currentPasswordType.type = 'text'; } else { currentPasswordType.type = 'password'; } } if (inputValue === 2) { var currentPasswordType = document.getElementById('newPassword'); if (currentPasswordType.type === 'password') { currentPasswordType.type = 'text'; } else { currentPasswordType.type = 'password'; } } if (inputValue === 3) { var currentPasswordType = document.getElementById('confirmPassword'); if (currentPasswordType.type === 'password') { currentPasswordType.type = 'text'; } else { currentPasswordType.type = 'password'; } } } </script> ?> <script> function readURL(input) { if (input.files && input.files[0]) { var reader = new FileReader(); reader.onload = function(e) { $('#actualImg') .attr('src', e.target.result); /* $('#initImg').hide(); */ }; reader.readAsDataURL(input.files[0]); } } </script>