PHP How do I get my form inputs to have data that is auto generated based on selection from database
<p>This is a bit hard for me to explain and I don't really have any examples to show as I don't know how to do it.</p>

<p>What I am trying to do is to have fields automatically filled up for me based on my selection which is taken from my database.</p>

<p>Let's say I'm trying to fill data up for a casualties form and I'm getting my selection for my fields from a people's database and that database contains all the information of everybody inside, information such as the contact number, next of kin, full name, their IC etc etc.</p>

<p>Is there a way to display data such contact number, next of kin, IC number based on let's say their name inside the form itself?
<a href="https://i.stack.imgur.com/TZ3dK.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/TZ3dK.png" alt="enter image description here"></a></p>

<pre><code>$query = "SELECT * FROM staff";
$result = mysqli_query($link, $query) or die(mysqli_error($link));
.... in the form itself
 &lt;tr&gt;
                &lt;td&gt;&lt;label&gt;&lt;b&gt;Staff ID&lt;/b&gt;&lt;/label&gt;&lt;/td&gt;
                &lt;td&gt;&lt;select name="staffID"&gt;&lt;option value=""&gt;Select staff ID&lt;/option&gt;
                        &lt;?php
                        while ($row = mysqli_fetch_assoc($result)) {
                            ?&gt;
                            &lt;option value="&lt;?php echo $row['staff_id']; ?&gt;"&gt;
                                &lt;?php echo $row['staff_id']; ?&gt;
                            &lt;/option&gt;
                        &lt;?php } ?&gt;
                    &lt;/select&gt;&lt;/td&gt;
&lt;/tr&gt;
</code></pre>

<p>The idea is, after they selected an ID from the dropdown box, additional fields will appear, giving the user more details of the staff such as their full name, contact number etc etc.</p>

<p>I can echo out all their ID and I know how to generate out additional fields but I don't know how to auto fill up data on those fields based on the staff_ID they selected. </p>

<p>Sorry if this is confusing, english is not my main language and I'm pretty terrible with programming</p>