if you don't want to use AJAX to dynamically load the content, you need a form to submit the data, your problem is that after your first loop, $firstname is the last user loaded into the , to make your code work, you need a form.
just put the select in a form and add a button
<form action="mypage.php" method="get">
<select name="name" style="width: 400px">
<?php
$sql = "SELECT first_name,last_name FROM registration_tbl";
$query = mysqli_query($dbc, $sql);
while ($row = mysqli_fetch_assoc($query)){
$firstname = $row['first_name'];
$lastname = $row['last_name'];
echo'<option>' . $firstname . " " . $lastname . '</option>';
}
?>
</select>
<input type="submit" value="Load User Data">
</form>
then in mypage.php you need to check if the form is submitted, and show the user details.
<?php
if(isset($_GET["name"])) {
//this form is posted, show user details
//$firstname = $_GET["name"]; <--- SQL Injection enabled here!!
$firstname = mysqli_real_escape_string($_GET["name"]); // please try to avoid SQL injection!
//your code continues here
$sql = "SELECT * FROM registration_tbl WHERE first_name = '".$firstname."'";
$query = mysqli_query($dbc, $sql);
while($row = mysqli_fetch_array($query)){
echo "ID: " . " " . $row[0] . "<br>" .
"Name: " . $row[1] . " " . $row[2] . "<br>" .
"Company: " . $row[3] . "<br> " .
"Email: " .$row[4] . "<br> " .
"Date of registration: " . $row[6] . "<br> " .
"Last login: " .$row[7] . "<br>" .
"Admin/User: " .$row[8] . "<p>";
}
}
last note, if you don't want the username to appear in the querystring, change form action to post, and get variable using $_POST["name"]
EDIT: if you want the form to autopost using javascript then add this to ur select definition:
<select name="name" style="width: 400px" onchange="this.form.submit()">
but bear in mind that a lot of users block javascript, thus this will not work.