I have this code that a programmer did in his day, This code does that through other php when selecting a game selects the one of mates. What I want to do is make two more games of subtraction and multiplication
<?php
session_start();
$host_name = "xxxx";
$database = 'xxxx';
$user_name = "xxxx";
$password = "xxxxx";
$conexion = mysqli_connect($host_name, $user_name, $password, $database) or die ("No se puede conectar a la base de datos");
if(isset($_SESSION['session'][2])) {
$usuario = $_SESSION['session'][2];
$guardar = "si";
}else{
$_SESSION['noregistrado'] = 'Invitado'.time();
$usuario = $_SESSION['noregistrado'];
$guardar = "no";
}
if(isset($_GET['acabado'])){
$respuesta2 = new \stdClass();
$respuesta2->final = $_SESSION['puntuacion'];
$respuesta2->usuario = $usuario;
$comprobar = "SELECT * FROM 'USUARIOS' WHERE 'usuario'='$usuario'";
$comprobar_q = mysqli_query($conexion,$comprobar) or die ("FALLA LA CONSULTA DE COMPROBACION");
$num = mysqli_num_rows($comprobar_q);
$puntuacion = $_SESSION['puntuacion'];
if($num==0){
$query = "INSERT INTO 'USUARIOS' VALUES ('$usuario','$puntuacion','SUMA 2 DIGITOS')";
}else{
$query = "UPDATE 'USUARIOS' SET 'puntuacion1'='$puntuacion' WHERE 'usuario'='$usuario'";
}
mysqli_query($conexion,$query) OR DIE ("FALLA LA CONSULTA DE INSERTAR");
$posicion = "SELECT 'usuario', 'puntuacion1', rank
FROM
(
SELECT 'usuario', 'puntuacion1', @n := IF(@g = puntuacion1, @n, @n + 1) rank, @g := puntuacion1
FROM 'USUARIOS', (SELECT @n := 0) i
ORDER BY 'puntuacion1' DESC) q WHERE 'puntuacion1' = '$puntuacion'";
$pos = mysqli_query($conexion,$posicion);
$posi = mysqli_fetch_assoc($pos);
$posic = $posi['rank'];
$respuesta2->posicion = $posic;
$respuesta2->guardado = $guardar;
if($guardar == 'no'){
$borrar = "DELETE FROM 'USUARIOS' WHERE 'usuario'='$usuario'";
mysqli_query($conexion,$borrar);
}
echo json_encode($respuesta2);
}else {
if (isset($_GET['respuesta'])) {
//TODO: comprobar tiempo
$clires = $_GET['respuesta'];
$respuesta = new \stdClass();
if ($clires == $_SESSION['num1'] + $_SESSION['num2']) {
$_SESSION['puntuacion']++;
$respuesta->mal = 1;
} else {
$respuesta->mal = 0;
}
$resultado = $_SESSION['num1'] + $_SESSION['num2'];
$respuesta->resultado = $resultado;
$_SESSION['num1'] = rand(10, 99);
$_SESSION['num2'] = rand(10, 99);
$operacion = $_SESSION['num1'] . '+' . $_SESSION['num2'] . '=';
$respuesta->operacion = $operacion;
$respuesta->ok = 1;
$respuesta->puntuacion = $_SESSION['puntuacion'];
echo json_encode($respuesta);
} else {
$_SESSION['puntuacion'] = 0;
//$_SESSION['gameStart']= timestamp();
$_SESSION['num1'] = rand(10, 99);
$_SESSION['num2'] = rand(10, 99);
$operacion = $_SESSION['num1'] . '+' . $_SESSION['num2'] . '=';
$respuesta = new \stdClass();
$respuesta->operacion = $operacion;
$respuesta->ok = 1;
echo json_encode($respuesta);
}
}
How can I make the correct operations when I select the subtraction game with id X?