<?php 

$max = 255;

$dir = '../../';

require_once $dir.'includes/main.php';

$errors = array();

$submit_message = filter_var($_POST['submit_message'], FILTER_SANITIZE_STRING);
$buy_message = filter_var($_POST['buy_message'], FILTER_SANITIZE_STRING);

if(strlen($submit_message) > $max || strlen($buy_message) > $max){
    $errors[] = "Messages must be less than $max characters";
}

// check errors
if(!empty($errors)){

    $_SESSION['messages'] = $errors;
    header("location: ../settings/messages");
    exit;

}else{

    if(query("UPDATE _settings SET submit_message = '{$submit_message}', buy_message = '{$buy_message}'")){

        $_SESSION['messages'][] = "Messages has been updated successfully";
        header("location: ../settings/messages");
        exit;

    }else{

        $_SESSION['messages'][] = "Error: could not update database";
        header("location: ../settings/messages");
        exit;

    }

}

?>