Removed unnecessary duplicated code for inserting new link to database
This commit is contained in:
parent
e56b67bae7
commit
71e028cfdb
@ -4,33 +4,10 @@
|
|||||||
}
|
}
|
||||||
$database = new Database ( $GLOBALS [ 'config' ] [ 'db' ] );
|
$database = new Database ( $GLOBALS [ 'config' ] [ 'db' ] );
|
||||||
$database->connect ( );
|
$database->connect ( );
|
||||||
if ( isset ( $_POST [ 'url' ] ) ) {
|
$database->prepare ( "SELECT links.ID, links.URL FROM links WHERE links.created_by = " . $_SESSION [ 'user_id' ] );
|
||||||
$url = $_POST [ 'url' ];
|
$database->execute ( );
|
||||||
$database->prepare ( "INSERT INTO `links` ( `ID`, `URL`, `created_by` ) VALUES ( NULL, ?, " . $_SESSION [ 'user_id' ] . " );" );
|
$result = $database->get_result ( );
|
||||||
$parameters = [
|
$row = $result->fetch_assoc ( );
|
||||||
[ "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 ( );
|
|
||||||
?>
|
?>
|
||||||
<!DOCTYPE html>
|
<!DOCTYPE html>
|
||||||
<html>
|
<html>
|
||||||
@ -59,5 +36,3 @@
|
|||||||
<script>var script_name = "<?=$GLOBALS['config']['installation_path']?>";</script>
|
<script>var script_name = "<?=$GLOBALS['config']['installation_path']?>";</script>
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
||||||
<?php
|
|
||||||
}
|
|
||||||
|
Reference in New Issue
Block a user