Not receiving reply from XAMPP

S

Skyler Ochsenbein

Guest
I have set up a server using XAMPP with a database already created. Using GameMaker Studio 2, I send a http_post_string request to a PHP script, however, the Asynchronous HTTP event is not called. I am at a loss as to why there is no callback. My PHP script works when I run it from my browser pre-setting the variables instead of using $_POST, so I know it's not a problem with the PHP portion.

Anyone have experience with this?

Code:
/// Retrieve one piece of random data from the database
var rank = irandom(4) + 1;
var gender = choose("male", "female");
var year = choose(2015, 2016, 2017);
var data = "rank=" + string(rank) + "&gender=" + gender + "&year=" + string(year);
retrieve_request = http_post_string("localhost/testing/retrieve.php", data);
PHP:
<?php
    header('Content-type: application/json');

    // Connect to the Database
    $connection = mysqli_connect("localhost", "root", "", "test");

    // Test connection
    if (!$connection)
        echo "Failed to connect";
    else {
        $table = "table_baby";
        $rank = $_POST["rank"];
        $gender = $_POST["gender"];
        $year = $_POST["year"];

        // Run the query
        $query = "SELECT name FROM $table WHERE rank = $rank AND gender = $gender AND year = $year";
        $result = mysqli_query($connection, $query);

        // Get the data
        if (mysqli_num_rows($result) == 1) {
            $data = mysqli_fetch_assoc($result);
        }
        else
            $data = ["name" => "Error..."];

        // Send back data to client
        echo $data["name"];
    }

    // Close the connection
    mysqli_close($connection);
?>
Code:
var result = "Request failed...";
if (async_load[? "id"] == retrieve_request) {
    if (async_load[? "status"] == 0)
        result = async_load[? "result"];
}
obj_messagebox.message = result;
 
Top