<?php
include "classes/class.loader.php";
$db = new db();

$target_dir = "../news_upload/";
$target_file = $target_dir . basename($_FILES["image"]["name"]);
$uploadOk = 1;
$imageFileType = strtolower(pathinfo($target_file, PATHINFO_EXTENSION));

// Check if $uploadOk is set to 0 by an error
if ($uploadOk == 0) {
    $image = null;
    // if everything is ok, try to upload file
} else {
    if (move_uploaded_file($_FILES["image"]["tmp_name"], $target_file)) {
        $image = $target_file;
    } else {
        $image = null;
    }
}
$heading = str_replace("'", "\'", $_POST['heading']);
$description = str_replace("'", "\'", $_POST['description']);
$db->query("UPDATE news SET `heading` = '$heading', `description` = '$description', `file_name` = '{$_FILES['image']['name']}' WHERE `record_id` = {$_POST['record_id']}");
echo "NEWS UPLOADED";