I've been running this code for about a week now, and did not get this problem until today. When I first load my web page, the database is initialized and the tables are created (if any of them do not already exist). However, on the same HTML page, I am calling a Javascript function to create a table of data from the database. This function call generates an error saying that the table does not exist in the database, but I logged onto WAMP and the table exists, and on subsequent loads (where the database already existed), the function works fine. What is going wrong here?
actions.js:
$(document).ready(function() {
    $.ajax({
        url: "action.php",
        type: "GET",
        data: { param1: "INITIALIZE"}
    });
    var json = [];
    //Function for getting decks from database
    function getDecks(hide) {
        $.ajax({
            url: "get_decks.php",
            type: "GET",
            data: {hideDecks : hide},
            success: function(data) {
                alert(data);
                json = JSON.parse(data);
                if(hide == "TRUE") {
                    createTable();
                } else {
                    createHideDeckTable();
                }
            }
        });
    }
}
action.php:
define("SERVER_NAME", "localhost");
define("USERNAME", "root");
define("PASSWORD", "");
define("DATABASE", "flashcards");
define("CHAPTERS_TABLE", "chapters");
define("DECKS_TABLE", "decks");
define("CARDS_TABLE", "cards");
//Function to execute database queries
function executeQuery($sql_query) {
    //Connecting to database
    $mysqli = mysqli_connect(SERVER_NAME, USERNAME, PASSWORD, DATABASE);
    //Check database connection
    if($mysqli === false) {
        die ("\nCould not connect:  " . mysqli_connect_error());
    }
    $result = mysqli_query($mysqli, $sql_query);
    if($result === false){
        echo nl2br("\n\nERROR: Could not able to execute $sql_query. " . mysqli_error($mysqli));
    }
    //Close database connection
    mysqli_close($mysqli);
}
//Function to execute database queries and return the result
function executeQueryWithResult($sql_query) {
    //Connecting to database
    $mysqli = mysqli_connect(SERVER_NAME, USERNAME, PASSWORD, DATABASE);
    //Check database connection
    if($mysqli === false) {
        die ("\nCould not connect:  " . mysqli_connect_error());
    }
    $rows = [];
    $result = mysqli_query($mysqli, $sql_query);
    if($result === false){
        echo nl2br("\n\nERROR: Could not able to execute $sql_query. " . mysqli_error($mysqli));
    } else {
        while($row = mysqli_fetch_assoc($result)) {
            $rows[] = $row;
        }
        return $rows;
    }
    //Close database connection
    mysqli_close($mysqli);
}
//This function initializes the database and all tables in the database
function initializeDatabase() {
    $mysqli = mysqli_connect(SERVER_NAME, USERNAME, PASSWORD);
    //Check database connection
    if($mysqli === false) {
        die ("\nCould not connect:  " . mysqli_connect_error());
    }
    //Query to create flashcards database
    $sql = "CREATE DATABASE IF NOT EXISTS " . DATABASE;
    mysqli_query($mysqli, $sql);
    //Set flashcards database as default database
    mysqli_select_db($mysqli, DATABASE);
    //Create the "Chapters" table
    $sql_create_chapters_table = "CREATE TABLE IF NOT EXISTS " . CHAPTERS_TABLE . "(
        chapter_ID INT NOT NULL PRIMARY KEY AUTO_INCREMENT,
        name VARCHAR(255) NOT NULL UNIQUE
        )";
    executeQuery($sql_create_chapters_table);
    //Create the "Decks" table
    $sql_create_decks_table = "CREATE TABLE IF NOT EXISTS " . DECKS_TABLE . "(
        deck_ID INT NOT NULL PRIMARY KEY AUTO_INCREMENT,
        chapter_ID INT NOT NULL,
        deck_description VARCHAR(255) NOT NULL,
        faculty BOOLEAN NOT NULL,
        hidden BOOLEAN NOT NULL,
        FOREIGN KEY (chapter_ID) REFERENCES chapters(chapter_ID)
        )";
    executeQuery($sql_create_decks_table);
    //Create the "Cards" table
    $sql_create_cards_table = "CREATE TABLE IF NOT EXISTS " . CARDS_TABLE . "(
        card_ID INT NOT NULL PRIMARY KEY AUTO_INCREMENT,
        deck_ID INT NOT NULL,
        front_text VARCHAR(255) NOT NULL,
        front_media VARCHAR(255),
        back_text VARCHAR(255) NOT NULL,
        back_media VARCHAR(255),
        FOREIGN KEY (deck_ID) REFERENCES decks(deck_ID)
        )";
    executeQuery($sql_create_cards_table);
    //Close database connection
    mysqli_close($mysqli);
}
//Process GET request
if(isset($_GET["param1"])) {
    $arg = $_GET["param1"];
    //"INITIALIZE" means database and tables should be created
    if($arg == "INITIALIZE") {
        initializeDatabase();
    }
}
get_decks.php:
include "action.php";
$sql_query = "SELECT * FROM " . DECKS_TABLE . " JOIN " . CHAPTERS_TABLE . " ON " . CHAPTERS_TABLE . ".chapter_ID=" . DECKS_TABLE . ".chapter_ID";
//Check whether or not hidden decks should be returned by the query
if(isset($_GET["hideDecks"])) {
    if(strcmp($_GET["hideDecks"], "TRUE")==0) {
        $sql_query .= " WHERE hidden=\"0\"";
    }
}
$rows = executeQueryWithResult($sql_query);
echo json_encode($rows);
index.html:
<!DOCTYPE html>
<html>
<head>
    <title>My Application</title>
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.0/jquery.min.js"></script>
    <script src="actions.js" type="text/javascript"></script>
</head>
<body>
    <h1 align="center">WELCOME TO MY APPLICATION</h1>
    <script>getDecks("TRUE");</script>
</body>
</html>
