Hello everyone, I am learning PHP with mySQL and I want to know if it's possible for me to do a dynamic dropdown box(which I have) that will automatically fill in fields below it such as a textbox. If I select a userID from the dropdown, that selection will fill in the first name, last name, etc... in the textboxes down below. Would that be possible for me to do?
This is what I have for now. Some information will be edited as some information is not meant to be seen
<!DOCTYPE html>
<html>
<body>
<?php
$servername = 'localhost';
$username = 'username';
$password = 'password';
$dbname = 'database';
//create connection
$conn = mysqli_connect($servername, $username, $password, $dbname);
//check connection
if(!$conn)
{
die("Connection Failed: " . mysqli_connect_error());
}
//lets you know that connection is successful
echo "Connected Successfully". "<br>";
//sql command to select parts of a table from the database and then sort them
$sql = "SELECT UserID from table group by UserID";
//The results are stored here
$result = mysqli_query($conn, $sql);
//Http lines of code in php syntax since we are using php after all
echo "<h1>". "HEADER". "</h1>";
echo "User ID:          ";
echo "<select name='dropdown'>";
echo "<option value='User ID'". ">". 'Drop down from Dropdown list'. "</option>";
//This will go through every entry in the table from the database
//and then put all the found entries in the dropdown menu.
while($row = mysqli_fetch_array($result))
{
//makes the entry visible in the dropdown menu
echo "<option value='". $row['UserID']."'>". $row['UserID']. "</option>";
}
echo "</select>";
echo "<br><br>";
echo "<form method=post>";
echo "First Name:    ". "<input type='text'". "placeholder='Enter first name'". "name='firstName'". ">";
echo "</form>";
//closes the connection to the database
mysqli_close($conn);
?>
</body>
</html>
Any help/information would be amazing. Thanks guys!