HEX
Server: Apache/2.4.58 (Ubuntu)
System: Linux ip-172-31-18-78 6.17.0-1017-aws #17~24.04.1-Ubuntu SMP Tue May 26 21:09:53 UTC 2026 aarch64
User: ubuntu (1000)
PHP: 8.2.31
Disabled: NONE
Upload Files
File: /var/www/nclive/technc/update_category.php
<?php
include 'header.php';

include '../wp-config.php';

// ABS_ADMIN_PATH

// ini_set('display_errors', 1);
// ini_set('display_startup_errors', 1);
// error_reporting(E_ALL);

$TABLE_POST = 'naukri_wp_posts';
$TABLE_POSTMETA = 'naukri_wp_postmeta';
$TABLE_YOAST_INDEXABLE = 'naukri_wp_yoast_indexable';
$TABLE_EXAM_CATEGORY = 'sp_exam_category';

// to get extension of uploaded image
function getExtension($str)
{
  $i = strrpos($str, ".");
  if (!$i) {
    return "";
  }
  $l = strlen($str) - $i;
  $ext = substr($str, $i + 1, $l);
  return $ext;
}

$user_id = 1;

$message = '';
$subQry = '';
$catid = $_REQUEST['id'];

$query = "Select cat_id,name,url_slug,h1_title,full_name,img_icon,display_order,type, status from $TABLE_EXAM_CATEGORY where cat_id = '$catid'";
$sql = $db->prepare($query);
$sql->execute();
$row = $sql->fetch();
if ($row['status'] == '1') {
  $status = "Active";
} else if ($row['status'] == '0') {
  $status = "Deactive";
}
/*----------get details for post name and slug--------*/
$slug = $row['url_slug'];
$checkPost = $db->prepare("SELECT ID FROM $TABLE_POST WHERE post_name='$slug'");
$checkPost->execute();
$rowPost = $checkPost->fetch();
$postID = $rowPost['ID'];
/*----------get details for meta values--------*/
$keywordQry = $db->prepare("SELECT meta_value FROM $TABLE_POSTMETA where post_id='$postID' AND meta_key='_yoast_wpseo_metakeywords'");
$keywordQry->execute();
$getMetaKeyword = $keywordQry->fetch();

$metadescQry = $db->prepare("SELECT meta_value from $TABLE_POSTMETA where post_id='$postID' AND meta_key='_yoast_wpseo_metadesc'");
$metadescQry->execute();
$getMetaDesc = $metadescQry->fetch();

$metakeyQry = $db->prepare("SELECT meta_value from $TABLE_POSTMETA where post_id='$postID' AND meta_key='_yoast_wpseo_focuskw'");
$metakeyQry->execute();
$getMetaKey = $metakeyQry->fetch();

$metatitleQry = $db->prepare("SELECT meta_value from $TABLE_POSTMETA where post_id='$postID' AND meta_key='_yoast_wpseo_title'");
$metatitleQry->execute();
$getMetaTitle = $metatitleQry->fetch();

 // update date
 if (isset($_REQUEST['submit'])) {
  $heading = $_REQUEST['heading'];
  $order = $_REQUEST['num'];
  $type = $_REQUEST['type'];

  $meta_title = $_REQUEST['metaTitle'];
  $meta_key = $_REQUEST['metafkeyword'];
  $meta_keyword = $_REQUEST['metaKeyword'];
  $meta_desc = $_REQUEST['metaDesc'];

  $userpic = $_REQUEST['image'];
  $target_dir = ABSPATH . "/images/"; // "/opt/naukriwp/images/";
  $file_name = basename($_FILES["exam_img"]["name"]);
  if ($file_name != NULL) {
    if (($_FILES["exam_img"]["size"] > 0)) {
      $fileName = $_FILES['exam_img']['name'];
      $fileSize = $_FILES['exam_img']['size'];
      $ext = strtolower(getExtension($fileName));
      $allowed_ext = ['jpg', 'jpeg', 'png', 'JPG', 'JPEG', 'PNG'];

      if (in_array($ext, $allowed_ext) === false) {
        $message = '<div class="alert alert-danger"><strong><h5>Please choose JPG,JPEG,PNG file,hence error on this file upload: ' . $fileName . ' </h5></strong></div>';
      } else if ($fileSize > 204800) {
        $message = '<div class="alert alert-danger"><strong>Please upload file upto 200 KB only.</strong></div>';
      } else {
        $icon_name = 'category_' . time() . "." . $ext;
        $target_dir = ABSPATH . "images/";  // =/opt/naukriwp/images/
        $target_file = $target_dir . $icon_name;
        // upload image to folder
        if (move_uploaded_file($_FILES['exam_img']['tmp_name'], $target_file)) {
          $subQry = ", img_icon='$icon_name'";
        } else {
          $error = '<div class="alert alert-danger"><strong> Image Upload unsuccessfull ! </strong></div>';
        }
      }
    } else {
      $msg = '<div class="alert alert-danger"><strong> Image size exceeds 200 KB </strong></div>';
    }
  }

  $query = "UPDATE sp_exam_category SET h1_title='$heading', display_order='$order' $subQry, type='$type' WHERE cat_id='$catid'";
  echo $query;
  $sql = $db->prepare($query);
  $sql->execute();
  // yoast seo data table and post meta
  update_post_meta($postID, '_yoast_wpseo_title', $meta_title);
  update_post_meta($postID, '_yoast_wpseo_focuskw', $meta_key);
  update_post_meta($postID, '_yoast_wpseo_metadesc', $meta_desc);
  update_post_meta($postID, '_yoast_wpseo_metakeywords', $meta_keyword);

  if ($sql->execute()) {
    $message = '<div class="alert alert-success"><strong>Data Updated successfully</strong></div>';
  } else {
    $message = '<div class="alert alert-danger"><strong>Error In Page Updation </strong></div>';
  }
}


?>

<main id="main-container">
  <div class="content content-narrow">
    <div class="row">
      <div class="col-lg-12">
        <h2 class="content-heading">Update Category Details </h2>
        <div class="block">
          <div class="block-header">
            <ul class="block-options">
              <li>
                <button type="button"><i class="si si-settings"></i></button>
              </li>
            </ul>
            <h3 class="block-title"></h3>
          </div>
          <div class="block-content block-content-narrow">

            <?php echo $message; ?>
            <form class="js-validation-bootstrap form-horizontal" method="post" action="update_category.php?id=<?php echo $catid; ?>" enctype="multipart/form-data">
              <div class="form-group">
                <label class="col-md-3 control-label" for="heading"> Category Title</label>
                <div class="col-md-8">
                  <input class="form-control" type="text" value="<?php echo $row['name']; ?>" readonly="readonly">
                </div>
              </div>
              <div class="form-group">
                <label class="col-md-3 control-label" for="val-password">Image icon</label>
                <div class="col-md-8">
                  <input class="form-control" type="file" id="exam_img" name="exam_img">
                  <input type="hidden" name="image" id="image">
                  <img src="/images/<?php echo $row['img_icon']; ?>" style="width:50px; height:50px;" />
                </div>
              </div>

              <div class="form-group">
                <label class="col-md-3 control-label" for="heading"> Hi Title</label>
                <div class="col-md-8">
                  <input class="form-control" type="text" name="heading" placeholder="Enter H1 Title" value="<?php echo $row['h1_title']; ?>">
                </div>
              </div>
              <div class="form-group">
                <label class="col-md-3 control-label" for="metaTitle"> Meta Title</label>
                <div class="col-md-8">
                  <input class="form-control" type="text" name="metaTitle" placeholder="Enter Meta Title" value="<?php echo $getMetaTitle['meta_value']; ?>">
                </div>
              </div>
              <div class="form-group">
                <label class="col-md-3 control-label" for="metafkeyword">Meta Focus Keyword</label>
                <div class="col-md-8">
                  <input class="form-control" type="text" name="metafkeyword" placeholder="Enter Meta Focus Keyword" value="<?php echo $getMetaKey['meta_value']; ?>">
                </div>
              </div>
              <div class="form-group">
                <label class="col-md-3 control-label" for="metaKeyword">Meta Keyword</label>
                <div class="col-md-8">
                  <input class="form-control" type="text" name="metaKeyword" placeholder="Enter Meta Keyword" value="<?php echo $getMetaKeyword['meta_value']; ?>">
                </div>
              </div>
              <div class="form-group">
                <label class="col-md-3 control-label" for="metaDesc">Meta Description</label>
                <div class="col-md-8">
                  <input class="form-control" type="text" name="metaDesc" placeholder="Enter Meta Description" value="<?php echo $getMetaDesc['meta_value']; ?>">
                </div>
              </div>
              <div class="form-group">
                <label class="col-md-3 control-label" for="val-password">Type<span class="text-danger">*</span></label>
                <div class="col-md-8">
                  <select name="type" class="form-control">
                    <option id="type" value=""></option>
                    <option value="1" <?php if ($row['type'] == '1') {
                                        echo "selected";
                                      } ?>>Government Exam</option>
                    <option value="2" <?php if ($row['type'] == '2') {
                                        echo "selected";
                                      } ?>>Entrance Exam</option>
                  </select>
                </div>
              </div>
              <div class="form-group">
                <label class="col-md-3 control-label" for="val-order">Display order<span class="text-danger">*</span></label>
                <div class="col-md-8">
                  <input class="form-control" type="number" id="display_order" name="num" placeholder="" value="<?php echo $row['display_order']; ?>">
                </div>
              </div>

              <div class="col-md-6">
              </div>
              <button type="submit" name="submit" class="btn btn-success">Update</button>
            </form>
          </div>
        </div>
      </div>
    </div>
  </div>
  </div>
</main>

<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.4/jquery.min.js"></script>

<script type="text/javascript">
  $(document).ready(function() {
    $("#type2").change(function() {
      var id = $(this).val();
      var dataString = 'id=' + id;

      $.ajax({
        type: "POST",
        url: "get_state_comm.php",
        data: dataString,
        cache: false,
        success: function(html) {
          $("#statecommission").html(html);
        }
      });
    });
  });
</script>

<script>
  //  to make slug from post name
  function convertToSlug(str) {
    str = str.replace(/[`~!@#$%^&*()_\-+=\[\]{};:'"\\|\/,.<>?\sā€˜ā€™//]/g, ' ').toLowerCase(); //replace all special characters | symbols with a space     
    str = str.replace(/^\s+|\s+$/gm, ''); // trim spaces at start and end of string
    str = str.replace(/\s+/g, '-'); // replace space with dash/hyphen
    document.getElementById("post_slug").value = str;
    document.getElementById('post_slug').readOnly = true;
  }
</script>

<?php include 'footer.php';  ?>