Below is the code to pull our client names from the db and show it as a dropdown menu:
<select name='client'>
<?php
print_r($client);
for ($x = 0; $x < count($client); $x++) {
echo ("<option value=".$client[$x]['clientName']."> ".$client[$x]['clientName']." <br>
</option>");
}
?>
</select>
After selecting the name and pressing the “submit” button, this value needs to be stored as the associated client ID because that is primary key in our table which is being used as foreign keys in other tables. I’m stuck at this point because I’m not sure how to convert this name to its corresponding ID. This is the code I’ve been trying to update to run this:
<?php
if (isset($_POST['submit'])) {
$getclientID = "SELECT * FROM ClientAccount WHERE clientName = '{client}' ";
$Client = getOneRow($getclientID);
$clientID = $Client['clientID'];
$clientID = $_POST['clientID'];
$query = "INSERT INTO ChildInformation (clientID) VALUES ('{$clientID}');";
runQuery($query);
echo'<span style="color:red;font-weight:bold;">Successful!</span>';
};
?>
For example, if I select “John Doe” from the dropdown menu and then press “submit” then it should be stored as “1” in the db because that’s John Doe’s client ID.
Thanks for your help!