From 71e028cfdbc523942653b83ae7de6fde09071459 Mon Sep 17 00:00:00 2001 From: Bryan Date: Wed, 29 May 2019 19:16:11 +0200 Subject: [PATCH] Removed unnecessary duplicated code for inserting new link to database --- lib/php/manage.php | 33 ++++----------------------------- 1 file changed, 4 insertions(+), 29 deletions(-) diff --git a/lib/php/manage.php b/lib/php/manage.php index c6343a2..4a22c9b 100644 --- a/lib/php/manage.php +++ b/lib/php/manage.php @@ -4,33 +4,10 @@ } $database = new Database ( $GLOBALS [ 'config' ] [ 'db' ] ); $database->connect ( ); - if ( isset ( $_POST [ 'url' ] ) ) { - $url = $_POST [ 'url' ]; - $database->prepare ( "INSERT INTO `links` ( `ID`, `URL`, `created_by` ) VALUES ( NULL, ?, " . $_SESSION [ 'user_id' ] . " );" ); - $parameters = [ - [ "s" ], - [ &$url ], - ]; - $database->bind ( $parameters ); - $database->execute ( ); - $database->prepare ( "SELECT MAX( links.ID ) as `last` FROM links;"); - $database->execute ( ); - $result = $database->get_result ( ); - $row = $result->fetch_assoc ( ); - header ( 'Content-Type: application/json' ); - $response = [ - 'status' => 200, - 'message' => 'URL inserted correctly.', - 'last_insert' => $row [ 'last' ], - ]; - echo ( json_encode ( $response ) ); - exit; - } - else { - $database->prepare ( "SELECT links.ID, links.URL FROM links WHERE links.created_by = " . $_SESSION [ 'user_id' ] ); - $database->execute ( ); - $result = $database->get_result ( ); - $row = $result->fetch_assoc ( ); + $database->prepare ( "SELECT links.ID, links.URL FROM links WHERE links.created_by = " . $_SESSION [ 'user_id' ] ); + $database->execute ( ); + $result = $database->get_result ( ); + $row = $result->fetch_assoc ( ); ?> @@ -59,5 +36,3 @@ -