<?php
if ( ! isset ( $_SESSION [ 'user_id' ] ) ) {
header ( 'Content-Type: application/json' );
http_response_code ( 401 );
$response = [
'status' => 401,
'error_message' => 'You either are not logged in or you do not have permissions to edit URLs.'
];
echo ( json_encode ( $response ) );
exit;
}
if ( ! isset ( $_POST [ 'url' ] ) ) {
http_response_code ( 400 );
'status' => 400,
'error_message' => 'You either did not provide a URL or you provided an invalid one.'
$database = new Database ( $config [ 'db' ] );
$database->connect ( );
$database->prepare ( "UPDATE `links` SET `URL`=:url WHERE `ID`=:url_id;" );
$database->bind ( [ ':url' => $_POST [ 'url' ], 'url_id' => $_POST [ 'url_id' ] ] );
$database->execute ( );
'status' => 200,
'message' => 'URL edited correctly.'