From b07c63051c06edb900a8b4817c2ec75366de5d74 Mon Sep 17 00:00:00 2001 From: Dorian HODIN Date: Mon, 28 Nov 2022 16:24:11 +0100 Subject: [PATCH] insertAndMakeListUser.php update --- .../script/insertAndMakeListUser.php | 20 ++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) diff --git a/Sources/php_script/script/insertAndMakeListUser.php b/Sources/php_script/script/insertAndMakeListUser.php index 1d3ca49..2c1db3e 100644 --- a/Sources/php_script/script/insertAndMakeListUser.php +++ b/Sources/php_script/script/insertAndMakeListUser.php @@ -26,7 +26,7 @@ function insertUserAndReturnList(): array|int $res = connection(); if (strcmp(gettype($res),"integer")==0) { - return 5; + return 2; } $query = "CREATE TABLE IF NOT EXISTS gps ( id varchar(30) PRIMARY KEY, @@ -37,6 +37,7 @@ function insertUserAndReturnList(): array|int );"; mysqli_query($res, $query); + if (!empty($_POST)) { //Check if the method POST return something $id = $_POST['id']; //Get the result of POST method @@ -52,16 +53,21 @@ function insertUserAndReturnList(): array|int $results = mysqli_query($connect, $query); */ - $query = "UPDATE gps SET latitude='$latitude', longitude='$longitude', idMusic='$idMusic' WHERE id='$id'"; //Delete the actual line and replace this line with the next lines + $query = "SELECT id FROM gps WHERE id = '$id' "; $results = mysqli_query($res, $query); //Execute the SQL command - if ($results==0){ + if (empty($results)){ $query = "INSERT INTO gps(id,latitude,longitude,idMusic,dateLog) VALUES('$id','$latitude','$longitude','$idMusic',CURRENT_TIMESTAMP);"; //Insert into the database the new data and new information about this user - mysqli_query($res, $query); + + }else{ + + $query = "UPDATE gps SET latitude='$latitude', longitude='$longitude', idMusic='$idMusic' WHERE id='$id'"; //Delete the actual line and replace this line with the next lines } + mysqli_query($res, $query); + $query = "SELECT * FROM gps WHERE id != '$id'"; //Browse all the database $results = mysqli_query($res, $query); //Execute the SQL command $listUser = []; //Set the listUser to an empty list @@ -82,13 +88,13 @@ function insertUserAndReturnList(): array|int } } if (!empty($listUser)){ - return 3; + return 2; } - return 2; + return 3; //Return an array } else { //If the method POST return nothing - return 4; //Return a code error + return 3; //Return a code error } }