File: /var/www/nclive/technc/state_edit.php
<?php
include 'header.php';
include '../wp-config.php';
// include 'sidebar.php';
// include 'top_header.php';
// include 'config.php';
$TABLE_POST = 'naukri_wp_posts';
$TABLE_POSTMETA = 'naukri_wp_postmeta';
$TABLE_YOAST_INDEXABLE = 'naukri_wp_yoast_indexable';
$TABLE_STATES = 'sp_states';
$state_id = $_REQUEST['state_id'];
$curDate = date('Y-m-d H:i:s', strtotime('+5 hour 30 minutes'));
$stateQuery = "Select * from $TABLE_STATES where state_id='$state_id'";
$sqlState = $db->prepare($stateQuery);
$sqlState->execute();
$rSt = $sqlState->fetch();
/*----------get details for post name and slug--------*/
$slug = $rSt['state_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();
if (isset($_POST['submit'])) {
$state_id = $_REQUEST['state_id'];
$horder = $_REQUEST['horder'];
$hstatus = $_REQUEST['hstatus'];
$statedesc = $_REQUEST['statedesc'];
$stateHead = $_REQUEST['heading'];
$meta_title = $_REQUEST['metaTitle'];
$meta_key = $_REQUEST['metafkeyword'];
$meta_keyword = $_REQUEST['metaKeyword'];
$meta_desc = $_REQUEST['metaDesc'];
$insertquery = "UPDATE $TABLE_STATES set header_order='$horder', header_status='$hstatus', h1_title='$stateHead', state_description ='$statedesc',update_by ='$user_id', update_date ='$curDate' where state_id='$state_id'";
$sql = $db->prepare($insertquery);
$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()) {
$msg = '<div class="alert alert-success"><strong> State details updated</strong></div>';
} else {
$msg = '<div class="alert alert-success"><strong>Data not updated, try again</strong></div>';
}
}
?>
<script type="text/javascript" charset="utf8" src="https://code.jquery.com/jquery-3.3.1.js"></script>
<?php
?>
<main id="main-container">
<div class="content content-narrow">
<div class="row">
<div class="col-lg-12">
<h2 class="content-heading"> Edit State Details</h2>
<div class="block">
<?php if (isset($msg)) {
echo $msg;
} ?>
<div class="block-content block-content-narrow">
<form class="js-validation-bootstrap form-horizontal" method="post" enctype="multipart/form-data">
<div class="form-group">
<label class="col-md-2" for="val-select2">State Name</label>
<div class="col-md-7">
<?php echo $rSt['state_name']; ?>
</div>
</div>
<div class="form-group">
<label class="col-md-2" for="val-select2">State Slug</label>
<div class="col-md-7">
<?php echo $rSt['state_slug']; ?>
</div>
</div>
<div class="form-group">
<label class="col-md-2" for="val-select2">State Code</label>
<div class="col-md-7">
<?php echo "[sh_state_list]"; ?>
</div>
</div>
<div class="form-group">
<label class="col-md-2" for="heading"> Hi Title</label>
<div class="col-md-7">
<input class="form-control" type="text" name="heading" placeholder="Enter H1 Title" value="<?php echo $rSt['h1_title']; ?>">
</div>
</div>
<div class="form-group">
<label class="col-md-2" for="metaTitle"> Meta Title</label>
<div class="col-md-7">
<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-2" for="metafkeyword">Meta Focus Keyword</label>
<div class="col-md-7">
<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-2" for="metaKeyword">Meta Keyword</label>
<div class="col-md-7">
<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-2" for="metaDesc">Meta Description</label>
<div class="col-md-7">
<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-2" for="val-email">Header Display Order</label>
<div class="col-md-7">
<input class="form-control" type="text" name="horder" id="title" value="<?php echo $rSt['header_order']; ?>" />
</div>
</div>
<div class="form-group">
<label class="col-md-2" for="val-password">Header Status</label>
<div class="col-md-7">
<select class="js-select2 form-control" name="hstatus" style="width: 100%;">
<option <?php if ($rSt['header_status'] == 1) echo "selected"; ?> value="1">Active</option>
<option <?php if ($rSt['header_status'] == 0) echo "selected"; ?> value="0">Deactive</option>
</select>
</div>
</div>
<div class="form-group">
<label class="col-md-2" for="val-email">State Description</label>
<div class="col-md-10">
<textarea class="ckeditor" name="statedesc"><?php echo $rSt['state_description']; ?></textarea>
</div>
</div>
<div class="form-group">
<div class="col-md-10 col-md-offset-2">
<input type="hidden" name="stateid" value="<?php echo $state_id; ?>" />
<button class="btn btn-lg btn-primary" name="submit" type="submit">Update</button>
</div>
</div>
</form>
</div>
</div>
</div>
</div>
</div>
</main>
<?php include 'footer.php'; ?>