Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

186
Vistas
Trying to fetch MySQL Data and display it in text fields using PHP - Nothing Happening when making my selection?

I am trying to pull through the corresponding use by date for the selected Stock Item. I have searched through my code and tried to re write it more than once and I just can't find where my error lies atall. When I am trying to run the code, I am able to select my Stock, but nothing happens when I make that selection. After choosing 'Inspect' on my webbrowser, it used to come up with a HTTP:500 Error but that seems to have gone and now just nothing is happening? Looking for a fresh pair of eyes to point me in the right direction if possible!

To note: I have used the following at the top of my html page in the section.

<script src="./fetchtraceability.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.6.0/jquery.min.js"></script>

SNIPPET FROM HTML PAGE:

<label for="labels">Stock:</label>
    <select id="stockid" name="Stock" onchange="fetchuseby()">
        <option>Select Stock</option>
            <?php
                $sqli = "SELECT Stock FROM stock WHERE Sector = 'Beef'";
                $result = mysqli_query($con, $sqli);
                while ($row = mysqli_fetch_array($result)) {
                    $k = $row['Stock'];
                    echo '<option value="'.$k.'">'.$k.'</option>';
                }
            ?>
    </select>
    <br>
    <br>
<label for="labels">Use By:</label>
    <input type="text" name="UseBy" id="usebyid">
    <br>
    <br>
    <input type="submit" value="Submit">

JS FUNCTION:

function fetchuseby(){
var id = document.getElementById("stockid").value;

$.ajax({
    url:"showuseby.php",
    method: "POST",
    data:{
        x : id
    },
    dataType: "JSON",
    success: function(data){
        document.getElementById("usebyid").value = data.UseBy
    }
})

}

PHP CODE:

<?php
ini_set('display_errors', 1); 
$server="localhost";
$userid="root";
$password="root";
$myDB="butchery_system_trial";

$con = mysqli_connect($server, $userid, $password, $myDB);

$k = $_POST["x"];
$sqli = "SELECT Use_By FROM stock WHERE Stock={$k}";
$result = mysqli_query($con, $sqli);
while ($rows = mysqli_fetch_array($result)) {
    $data['UseBy'] = $rows["Use_By"];
}

echo json_encode($data);

?>

about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

your all code is currect.please check connection information.i think connection password is blank not root

about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda