how do I bring records with select?

0

I have this code connected to a database with a I want to bring me the data related to that registry but it does not work for me I'm using ajax.

getuser.php

<html>
  <head>
   <script>
      function showUser(str) {
        if (str == "") {
            document.getElementById("txtHint").innerHTML = "";
            return;
        } else {
               if (window.XMLHttpRequest) {
               // code for IE7+, Firefox, Chrome, Opera, Safari
               xmlhttp = new XMLHttpRequest();
               } else {
               // code for IE6, IE5
               xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
               }
           xmlhttp.onreadystatechange = function() {
           if (this.readyState == 4 && this.status == 200) {
              document.getElementById("txtHint").innerHTML = 
           this.responseText;
           }
        };
        xmlhttp.open("GET","getuser.php?q="+str,true);
        xmlhttp.send();
     }
    }
   </script>
</head>
<body>

<form>
  <select name="users" onchange="showUser(this.value)">
   <option value="">Select a placa:</option>
   <option value="1">IEQ-524</option>
   <option value="2">MOW-930</option>
   <option value="3">MOW-931</option>
   <option value="4">OKL-227</option>
   <option value="4">TRG-542</option>
   <option value="4">TRG-544</option>
  </select>
 </form>
 <br>
 <div id="txtHint"><b>Person info will be listed here...</b></div>

 </body>
 </html> 

modify.php

<!DOCTYPE html>
<html>
<head>
  <style>
    table {
    width: 100%;
    border-collapse: collapse;
}

table, td, th {
    border: 1px solid black;
    padding: 5px;
}

th {text-align: left;}
</style>
</head>
<body>

<?php
$q = intval($_GET['q']);

$con = mysqli_connect('localhost','root','admin123','database');
if (!$con) {
    die('Could not connect: ' . mysqli_error($con));
}

mysqli_select_db($con,"ajax_demo");
$sql="SELECT * FROM ambulancia WHERE placa = '".$q."'";
$result = mysqli_query($con,$sql);

echo "<table>
<tr>
<th>placa</th>
<th>estado</th>
<th>Tipo Ambulancia</th>
</tr>";
while($row = mysqli_fetch_array($result)) {
    echo "<tr>";
    echo "<td>" . $row['placa'] . "</td>";
    echo "<td>" . $row['estado'] . "</td>";
    echo "<td>" . $row['tipo_Ambulancia'] . "</td>";
    echo "</tr>";
}
echo "</table>";
mysqli_close($con);
?>
</body>
</html> 
    
asked by cristian trujillo 03.04.2018 в 04:24
source

1 answer

2

In your ajax call you should point to your file modify.php:

xmlhttp.open("GET","modificar.php?q="+str,true);
    
answered by 03.04.2018 в 05:00