I have this hidden input box where I store my table's IDs. I want to get this input value and send it to a my SQL Query in the same file: problem is, nothing i've done has worked.
My input box, that stores the values:
<input  name='theNum3' id='theNum3'>
Here's how I store the value:
$("#companieSelect").change(function() {
    $("input[name='theNum3']").val($(this).val());
});
And this is my query:
$result = $conn->query("SELECT empresas.nome, departamentos.nomeDepartamento, funcionarios.nomeFuncionario, funcionarios.email, funcionarios.idFuncionarios FROM empresas INNER JOIN departamentos ON empresas.id = [HERE] INNER JOIN funcionarios ON departamentos.id = funcionarios.idDepartamentos ORDER BY empresas.nome ASC ") or die($conn->error);
Here's the connections and HTML files:
<?php
    require 'includes/dbh.inc.php';
    $result = $conn->query("SELECT * from empresas") or die($conn->error);
?>
<div class="form-group" >
    <select style = "justify-content: center; display: flex;margin-left: 20%; 
        margin-right: auto; margin-top: 5%" name="companieSelect" 
        class="form-control" id="companieSelect"  >
        <option value="" disabled selected> Selecione a empresa </option>
            <?php
                  while ($row = $result->fetch_assoc()) : ?>
                      <option value="<?= $row['id']; ?>"> <?= $row['nome']; ?> 
                      </option>
           <?php endwhile ?>
    </select>
</div>
<input  name='theNum3' id='theNum3'>
<script> 
    function getInput() {
        var x = document.getElementById("theNum3").value;
    }
</script>
 
<?php
    require 'includes/dbh.inc.php';
    $result = $conn->query("SELECT empresas.nome, departamentos.nomeDepartamento, 
    funcionarios.nomeFuncionario, funcionarios.email, funcionarios.idFuncionarios FROM empresas INNER 
    JOIN departamentos ON empresas.id = departamentos.idEmpresas INNER JOIN funcionarios ON 
    departamentos.id = funcionarios.idDepartamentos ORDER BY empresas.nome ASC ") or die($conn->error);
?>
Thank you for your help!
 
    