insertAndMakeListUser.php update
continuous-integration/drone/push Build is passing Details

remotes/origin/mvc-implementation
Dorian HODIN 2 years ago
parent 4558b4c64a
commit b07c63051c

@ -26,7 +26,7 @@ function insertUserAndReturnList(): array|int
$res = connection(); $res = connection();
if (strcmp(gettype($res),"integer")==0) { if (strcmp(gettype($res),"integer")==0) {
return 5; return 2;
} }
$query = "CREATE TABLE IF NOT EXISTS gps ( $query = "CREATE TABLE IF NOT EXISTS gps (
id varchar(30) PRIMARY KEY, id varchar(30) PRIMARY KEY,
@ -37,6 +37,7 @@ function insertUserAndReturnList(): array|int
);"; );";
mysqli_query($res, $query); mysqli_query($res, $query);
if (!empty($_POST)) { //Check if the method POST return something if (!empty($_POST)) { //Check if the method POST return something
$id = $_POST['id']; //Get the result of POST method $id = $_POST['id']; //Get the result of POST method
@ -52,16 +53,21 @@ function insertUserAndReturnList(): array|int
$results = mysqli_query($connect, $query); $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 $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 $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 $query = "SELECT * FROM gps WHERE id != '$id'"; //Browse all the database
$results = mysqli_query($res, $query); //Execute the SQL command $results = mysqli_query($res, $query); //Execute the SQL command
$listUser = []; //Set the listUser to an empty list $listUser = []; //Set the listUser to an empty list
@ -82,13 +88,13 @@ function insertUserAndReturnList(): array|int
} }
} }
if (!empty($listUser)){ if (!empty($listUser)){
return 3; return 2;
} }
return 2; return 3; //Return an array
} else { //If the method POST return nothing } else { //If the method POST return nothing
return 4; //Return a code error return 3; //Return a code error
} }
} }

Loading…
Cancel
Save