0
0

Added new lines at the end of files, added edit functionality

This commit is contained in:
Bryan
2019-06-02 14:46:51 +02:00
parent ed20989e14
commit 312d03599f
13 changed files with 137 additions and 11 deletions

View File

@@ -0,0 +1,33 @@
<?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' ] ) ) {
header ( 'Content-Type: application/json' );
http_response_code ( 400 );
$response = [
'status' => 400,
'error_message' => 'You either did not provide a URL or you provided an invalid one.'
];
echo ( json_encode ( $response ) );
exit;
}
$database = new Database ( $GLOBALS [ '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 ( );
header ( 'Content-Type: application/json' );
$response = [
'status' => 200,
'message' => 'URL edited correctly.'
];
echo ( json_encode ( $response ) );
exit;