I
I
iamdivine2020-04-27 22:21:41
PHP
iamdivine, 2020-04-27 22:21:41

How to make the separation of incoming information in the database through $_GET?

Goodnight! I'm struggling with a logical solution to a problem.
Data comes to the server that contains the HWID of the PC and information about it, sometimes the pcname field can be the same for two ownerid at the same time, how to make sure that each owner id receives data that came to him, and if the ownerid and pcname match, then just update the info field rather than creating a new one. I made this code, but got confused
5ea730a9ac693614772978.png

$pcname = $_GET['a'];
$info = $_GET['str'];
$owner = $_GET['own'];

$stmt = $pdo->prepare("SELECT * FROM sloader ORDER BY pcname=?");
$stmt->execute([$pcname]);
$pcinfo = $stmt->fetch();

if ($pcinfo['ownerid'] != $owner && !$pcinfo['pcname']) { // если не существует
    $sql = "INSERT INTO sloader (ownerid, pcname, info, dLink) VALUES (?,?,?,?)";
    $pdo->prepare($sql)->execute([$owner, $pcname, $info , 0]);
    $pdo = null;
} else {
    $sql = "UPDATE sloader SET info=? WHERE pcname=?";
    $stmt= $pdo->prepare($sql);
    $stmt->execute([$info, $pcname ]);
}

I really ask for your help

Answer the question

In order to leave comments, you need to log in

1 answer(s)
R
Rsa97, 2020-04-27
@iamdivine

Composite UNIQUE index on ownerid and pcname. INSERT ... ON DUPLICATE KEY UPDATE query

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question