I am very new to this and this is my first post to stackoverflow. I am simply trying to: Create a dropdown list that 1) Triggers a query (Gettech.php) everytime it changes 2) Updates another field with the results of the query
In this case they select a "tech name" and it should update another field with the associated "tech number" (result of the PDO query) everytime "tech name" changes. This is what I have:
<!DOCTYPE HTML>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<script src="https://code.jquery.com/jquery-1.12.4.js"></script>
<script src="https://code.jquery.com/ui/1.12.1/jquery-ui.js"></script>
</head>
<body>
<form action="Gettech.php" method="get">
<div class="row">
<div class="col-sm-6 form-group">
<label for="name"> Name:</label>
<select class= "form-control" id="techname" name=techname><option value="">Select...</option>
<option value="First Name">First Name</option>
<option value="Second Name">Second Name</option> .
.
.
</select>
</div>
</form>
</body>
</html>
and the Gettech.php part
<?php
$servername = "localhost";
$username = "####";
$password = "####";
$name = "Joey";
try {
$db = new PDO('mysql:host=localhost;dbname=staff', $username, $password);
} catch (PDOException $e) {
echo $e->getMessage()."<br>";
die();
}
$sql = "SELECT name, techid from techs where name= '$name'";
foreach( $db->query($sql) as $row ) {
echo $row['name']."<br>".$row['techid']."<br>";
}
$db = null;
?>
Individually they work but don't know how to tie them together into a working solution. Hints are welcome!
</div>