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_sp_other_links.php
<?php
// error_reporting(E_ALL);
// ini_set('display_errors', 'ON');

include 'header.php';
$user_id = $_SESSION['user_id'];
$id = $_REQUEST['id'];

$update_other_query = "SELECT link.id, link.post_name, link.post_slug, link.logo, link.summary, link.description, link.post_by, link.post_date, link.status, link.last_update_by, link.last_update_date,link.state_slug, state.state_name FROM sp_other_links as link LEFT JOIN sp_states as state on state.state_slug=link.state_slug WHERE id='$id'";
$other_sql = $db->prepare($update_other_query);
$other_sql->execute();
$other_row = $other_sql->fetch();
$image_path = $url . "/all_uploads/";
$curDate = date('Y-m-d H:i:s');

if (isset($_REQUEST['submit'])) {

    $post_name = $_REQUEST['post_name'];
    $post_slug = $_REQUEST['post_slug'];
    $summary = $_REQUEST['summary'];
    $description = $_REQUEST['description'];
    $post_by = $_REQUEST['post_by'];
    $status = $_REQUEST['status'];
    $user_id = $_REQUEST['user_id'];
    $state = $_REQUEST['state'];

    $errors = []; // Store all foreseen and unforseen errors here
    $fileExtensions = ['jpg', 'jpeg', 'png']; // Get all the file extensions

    $fileName = $_FILES['myfile']['name'];
    $fileSize = $_FILES['myfile']['size'];
    $fileTmpName  = $_FILES['myfile']['tmp_name'];
    $fileType = $_FILES['myfile']['type'];
    $ext = pathinfo($fileName, PATHINFO_EXTENSION);
    $fileExtension = strtolower(end(explode('.', $fileName)));

    $target_dir = "/var/www/nclive/all_uploads/";
    if ($fileName != '') {
        if (!in_array($ext, $fileExtensions)) {
            $message = "<font style='color:red; float:left;'><h5>Please choose jpg, png, jpeg file <br>error on this file: " . $fileName . " </h5></font>";
        } else {
            if (!is_dir($target_dir)) {
                mkdir($target_dir, 0777, true);
                $target_file = $target_dir . $fileName;
                $didUpload = move_uploaded_file($_FILES['myfile']["tmp_name"], $target_file);
            } else {
                $target_file = $target_dir . $fileName;
                $didUpload = move_uploaded_file($_FILES['myfile']["tmp_name"], $target_file);
                print_r($didUpload);
            }

            if ($fileSize > 10000000) {
                $errors[] = "This file is more than 2MB. Sorry, it has to be less than or equal to 2MB";
            }
        }
        if ($_REQUEST['post_slug'] != '') {
            $update_query = "UPDATE sp_other_links SET post_name='$post_name', post_slug='$post_slug', summary='$summary', description='$description', status='$status', last_update_by='$user_id', last_update_date='$curDate', logo='$fileName', state_slug='$state' WHERE id='$id'";
        }
    } else {
        if ($_REQUEST['post_slug'] != '') {
            $update_query = "UPDATE sp_other_links SET post_name='$post_name', post_slug='$post_slug', summary='$summary', description='$description', status='$status', last_update_by='$user_id', last_update_date='$curDate', state_slug='$state' WHERE id='$id'";
        }
    }

    $sql = $db->prepare($update_query);
    if ($sql->execute()) {
        // echo '<h3 style="color:green;">Data Update successfully</h3>';
        // echo "<meta http-equiv='refresh' content='0'>";

        $lastid = $db->lastInsertId();

        $record = "INSERT INTO sp_exam_update SET exam_id='$name', type='U', user_id='$user_id', date='$curDate', description='$title'";
        $sql2 = $db->prepare($record);
        $sql2->execute();

        echo '<h3 style="color:green;">Data Update successfully</h3>';
        echo "<meta http-equiv='refresh' content='0'>";
    } else {
        echo "Update unsuccessfull!";
    }
}

?>

<main id="main-container">
    <div class="content content-narrow">
        <div class="row">
            <div class="col-lg-12">
                <h1 class="content-heading">Update Sp Other Links </h1>
                <div class="block">
                    <div class="block-header">
                        <ul class="block-options">
                            <li>
                                <button type="button"><i class="si si-settings"></i></button>
                            </li>
                        </ul>
                        <h4 class="block-title"><?php echo @$message; ?></h4>
                    </div>

                    <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 control-label" for="val-username">Post Name</label>
                                <div class="col-md-10">
                                    <input class="form-control" type="text" name="post_name" value="<?php echo $other_row['post_name']; ?>">
                                </div>
                            </div>

                            <div class="form-group">
                                <label class="col-md-2 control-label" for="val-password">Post Slug</label>
                                <div class="col-md-10">
                                    <input class="form-control" type="text" name="post_slug" value="<?php echo $other_row['post_slug']; ?>">
                                </div>
                            </div>
                            <div class="form-group">
                                <label class="col-md-2 control-label" for="val-select2">Select State</label>
                                <div class="col-md-10">
                                    <select class="js-select2 form-control" id="type2" name="state">
                                        <?php
                                        $sql = $db->prepare("SELECT state_slug,state_id,state_name FROM sp_states");
                                        $sql->execute();
                                        ?>
                                        <option selected="selected" value="<?php echo $other_row['state_slug']; ?>"><?php echo $other_row['state_name']; ?></option>
                                        <?php
                                        while ($row = $sql->fetch(PDO::FETCH_ASSOC)) {
                                        ?>
                                            <option value="<?php echo $row['state_slug']; ?>"><?php echo $row['state_name']; ?></option>
                                        <?php
                                        } ?>
                                    </select>
                                </div>
                            </div>

                            <input type="hidden" name="user_id" value="<?php echo $user_id; ?>">


                            <div class="form-group">
                                <label class="col-md-2 control-label" for="val-password">Logo</label>
                                <div class="col-md-7">
                                    <input class="form-control" type="file" name="myfile" value="<?php echo $other_row['logo']; ?>">
                                    <label class="error" style="color:red;">Only JPG , PNG, JPEG files:</label>
                                </div>
                                <div class="col-md-3">
                                    <img src="<?php echo $image_path . $other_row['logo']; ?>" height="100" width="100">
                                </div>

                            </div>

                            <div class="form-group">
                                <label class="col-md-2 control-label" for="val-confirm-password">Summary</label>
                                <div class="col-md-10">
                                    <textarea class="ckeditor" name="summary" id="editor3"><?php echo $other_row['summary']; ?></textarea>
                                </div>
                            </div>

                            <div class="form-group">
                                <label class="col-md-2 control-label" for="val-confirm-password">Description</label>
                                <div class="col-md-10">
                                    <textarea class="ckeditor" name="description" id="editor3"><?php echo $other_row['description']; ?></textarea>
                                </div>
                            </div>

                            <div class="form-group">
                                <label class="col-md-2 control-label" for="val-password">Status:<span class="text-danger">*</span></label>
                                <div class="col-md-7">
                                    <select class="js-select2 form-control" name="status" style="width: 100%;">
                                        <option value="1" <?php if ($other_row['status'] == 1) {
                                                                echo "selected";
                                                            } ?>>Active</option>
                                        <option value="0" <?php if ($other_row['status'] == 0) {
                                                                echo "selected";
                                                            } ?>>Deactive</option>
                                    </select>
                                </div>
                            </div>

                            <div class="form-group">
                                <div class="col-md-10 col-md-offset-2">
                                    <button class="btn btn-lg btn-primary" name="submit" type="submit">Submit</button>
                                </div>
                            </div>
                        </form>
                    </div>
                </div>
            </div>
        </div>
    </div>
</main>

<style>
    .image {
        border: 1px solid;
        padding: 107px 3px 10px 123px;
        text-align: center;
    }
</style>

<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.4/jquery.min.js"></script>
<script src="https://ajax.aspnetcdn.com/ajax/jquery.validate/1.9/jquery.validate.min.js"></script>

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