I have combobox that loads the value from data base. I want when user select value from the combobox the form should load the corresponding values from database into html form. Here is code I am trying:
<div class="col-lg-6" style="display:none" id="c" >
<form id="aa" action="" method="post" >
<br><br><br>
<select name="id" id="id" class="span2" style=" width:150px;" onChange="this.form.submit();">
<?php
$servername = "localhost";
$username = "root";
$password = "";
$dbname = "valet";
// Create connection
$conn = mysqli_connect($servername, $username, $password, $dbname);
// Check connection
if (!$conn) {
die("Connection failed: " . mysqli_connect_error());
}
$arr = array();
$sql = "SELECT id FROM tbl_user ";
$result = mysqli_query($conn, $sql);
// echo "User name=" . $row["name"]. "<br>";
?>
<option value="">-select user-</option>
<?php
if (mysqli_num_rows($result) > 0) {
// output data of each row
while($row = mysqli_fetch_assoc($result)) {
$arr[] = $row;
}
foreach($arr as $key => $row){
echo "<option value='".$row["id"]."'>".$row["id"]."</option>";
$GLOBALS['a'] = $row["first_name"];
$GLOBALS['b'] = $row["last_name"];
$GLOBALS['c'] = $row["phone"];
$GLOBALS['d'] = $row["company_id"];
$GLOBALS['e'] = $row["register_on"];
}
}
else {
echo "Error: " . $sql . "<br>" . mysqli_error($conn);
header('Location: webservices.php');
}
mysqli_close($conn);
?>
</select>
<br><br><br>
<input type="text" id="first_name" value="<?php $GLOBALS['a'] ?>" name="first_name" style="width: 460px;height: 50px;overflow: hidden;" placeholder="First Name*">
<br><br><br><br>
<input type="text" id="last_name" value="<?php $GLOBALS['b'] ?>" name="last_name" style="width: 460px;height: 50px;overflow: hidden;" placeholder="Last Name*">
<br><br><br><br>
<input type="text" id="phone" value="<?php $GLOBALS['c'] ?>" name="phone" style="width: 460px;height: 50px;overflow: hidden;" placeholder="Phone*">
<br><br><br><br>
<input type="text" id="company_id" value="<?php $GLOBALS['d'] ?>" name="company_id" style="width: 460px;height: 50px;overflow: hidden;" placeholder="Company ID*">
<br><br><br><br>
<input type="text" id="register_on" value="<?php $GLOBALS['e'] ?>" name="register_on" style="width: 460px;height: 50px;overflow: hidden;" placeholder="Register On*">
<br><br><br><br>
<button name="edituser" id="edituser" type="submit" style="border:0;width:100px;margin-left: 45px;" >
<img src="images/save.png" alt="">
</button>
<button type="submit" style="border:0;width:100px;margin-left: 75px;">
<img src="images/cancel.png" alt="">
</button>
</form>
</div>
Please help me how I can accomplish this task?