blob: 725a005414216dd84b3d4d7aac9f627176b1ad7f (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
|
<?php
if (isset($_POST["UserID"]) && isset($_POST["PublicKeyString"])) {
require "DataBaseConf.php";
$CheckIfAlreadySetStmt = $conn->prepare("SELECT count(*) FROM `PublicKeys` WHERE UserID = :UserID");
$CheckIfAlreadySetStmt->bindValue(':UserID', $_POST['UserID']);
$CheckIfAlreadySetStmt->execute();
$CheckIfAlreadySetRes = $CheckIfAlreadySetStmt->fetchColumn();
if ($CheckIfAlreadySetRes == 1) {
$UpdatePublicKeyStmt = $conn->prepare("UPDATE `PublicKeys` SET PublicKeyString = :PublicKeyString WHERE UserID = :UserID");
$UpdatePublicKeyStmt->execute(array('PublicKeyString' => $_POST["PublicKeyString"], 'UserID' => $_POST["UserID"]));
} else if ($CheckIfAlreadySetRes == 0) {
$InsertPublicKeyStmt = $conn->prepare("INSERT INTO `PublicKeys` (UserID, PublicKeyString) VALUES (:UserID, :PublicKeyString)");
$InsertPublicKeyStmt->execute(array('PublicKeyString' => $_POST["PublicKeyString"], 'UserID' => $_POST["UserID"]));
}
} else {
http_response_code(400);
}
|