0

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!

Raven
  • 71
  • 2
  • 7
  • 1
    So submit a form or make an Ajax call to the server. – epascarello Sep 21 '20 at 02:16
  • Does your `getInput` function in js anything useful? From what I have known, you have to make a ajax `GET` or `POST` request in your `getInput` function. – Ahashan Alam Sojib Sep 21 '20 at 02:34
  • I was just testing getInput to see if a could convert a JS variable to a PHP one. – Raven Sep 21 '20 at 02:40
  • ** I want to get this input value and send it to a my SQL Query in the same file:** by using the value in the query what you wan to do? – Nasik Ahd Sep 21 '20 at 05:50
  • You should probably go and read [What is the difference between client-side and server-side programming?](https://stackoverflow.com/questions/13840429/) first of all. – 04FS Sep 21 '20 at 08:25

0 Answers0