php - How can I transfer parameters with axios and get method? ← (PHP, Vue.js, MySQL)

one text

I'm new to Vue.js and I'm trying to use it as front end while using only php to request my database.

I'm trying to use axios like this to request data from another php page :

getHoraires: function() {
                axios.get('api/horaires.php')
                    .then(function(response) {
                        console.log(response.data);
                        app.horaires = response.data;

                    })
                    .catch(function(error) {
                        console.log(error);
                    });
            },

I'd like to add one parameter in my request but I'm having an error 404 doing so :

getHoraires: function() {
                axios.get('api/horaires.php', {
                    params: {
                        rayon: 'IT'
                    }
                })
                    .then(function(response) {
                        console.log(response.data);
                        app.horaires = response.data;

                    })
                    .catch(function(error) {
                        console.log(error);
                    });
            },

Here's the code i'm using in my php page :

  $con = mysqli_connect($host, $user, $password, $dbname);

$method = $_SERVER['REQUEST_METHOD'];
$request = explode('/', trim($_SERVER['PATH_INFO'], '/'));
//$input = json_decode(file_get_contents('php://input'),true);


if (!$con) {
    die("Connection failed: " . mysqli_connect_error());
}


switch ($method) {
    case 'GET':
        $rayon = $_GET['rayon'];
        $sql = "select * from horaire" . ($rayon ? " where rayon=$rayon" : '');
        break;
    case 'POST':
        $numero = $_POST["numero"];
        $date = $_POST["date"];
        $type = $_POST["type"];
        $rayon = $_POST["rayon"];
        $modifNumero = $_POST["modifNumero"];
        $modifDate = $_POST["modifDate"];

        $sql = "insert into horaire (numero, date, type, rayon, modifNumero, modifDate) values ('$numero', '$date', '$type', '$rayon', '$modifNumero', '$modifDate')";
        break;
}

// run SQL statement
$result = mysqli_query($con, $sql);

// die if SQL statement failed
if (!$result) {
    http_response_code(404);
    die(mysqli_error($con));
}

if ($method == 'GET') {
    if (!$rayon) echo '[';
    for ($i = 0; $i < mysqli_num_rows($result); $i++) {
        echo ($i > 0 ? ',' : '') . json_encode(mysqli_fetch_object($result));
    }
    if (!$rayon) echo ']';
} elseif ($method == 'POST') {
    echo json_encode($result);
} else {
    echo mysqli_affected_rows($con);
}

Does anybody have a clue ? Tanks a lot !

Source