Removed unnecessary duplicated code for inserting new link to database
This commit is contained in:
parent
e56b67bae7
commit
71e028cfdb
@ -4,29 +4,6 @@
|
||||
}
|
||||
$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 ( );
|
||||
@ -59,5 +36,3 @@
|
||||
<script>var script_name = "<?=$GLOBALS['config']['installation_path']?>";</script>
|
||||
</body>
|
||||
</html>
|
||||
<?php
|
||||
}
|
||||
|
Reference in New Issue
Block a user