I'm trying to execute this function:
<?php
function registerDevice(){
        $query = "INSERT INTO devices (device,username) VALUES (:device,:username)";
         $query_params = array(
        ':device' => $_POST['device'],
        ':username' => $_POST['username'],
    );
        try {
        $stmt   = $db->prepare($query);
        $result = $stmt->execute($query_params);
    }
    catch (PDOException $ex) {
        $response["success"] = 0;
        $response["result"] = "Error154";
        die(json_encode($response));
    }
    }
registerDevice();
?>
The method is works successfully if is not called when is outside the function:
<?php
$query = "INSERT INTO devices (device,username) VALUES (:device,:username)";
             $query_params = array(
            ':device' => $_POST['device'],
            ':username' => $_POST['username'],
        );
            try {
            $stmt   = $db->prepare($query);
            $result = $stmt->execute($query_params);
        }
        catch (PDOException $ex) {
            $response["success"] = 0;
            $response["result"] = "Error154";
            die(json_encode($response));
        }
?>
but when i call the function the function does not work at all. I hope you guys can help me out. Thanks
 
     
     
    