Log in

View Full Version : populate php form with mysql after selecting drop down



kripper
02-15-2015, 11:54 PM
Hello.

New to the forum and new to PHP. Working hard to learn all I can, but at the moment, I appear to be completely lost.

I am trying to create a form for coaching my team, and I have it the drop down working so it pulls my team name from a MYSQL database, now I am trying to have it so, depending on which team member I select, it will populate other data from the database. Such as employee number, birth date, contact information.

Every time I think I have it working, I fail miserably.

Currently, this is the script I am using, but am failing at trying to get it to work correctly.


<?PHP

$db_host="localhost";
$db_user="root";
$db_password="test";
$db_name="master";

$cn=mysql_connect($db_host,$db_user,$db_password) or die(mysql_error());
mysql_select_db($db_name,$cn) or die(mysql_error());
$sql = "SELECT fullname, id, birthday FROM employees";
$rs = mysql_query($sql) or die(mysql_error());
echo "<select>";
while($row = mysql_fetch_array($rs)){
echo "<option value='".$row["fullname"]."'>".$row["fullname"]."</option>";
echo "</select>";
echo "<br />";
echo "<tr>";
echo "<td>Nordia ID:". $row['id']. "</td>";
echo "<br />";
echo "<td>Supervisor:". $row['birthday']. "</td>";
echo "<br />";
echo "</tr>";
}mysql_free_result($rs);

Presently, if i remove the echo "</select>"; it will only display the drop down with the MYSQL populated list. If I leave it in, if fills all of the page with all of the data I requested, simply, without the drop-down choice.

Please help guide this stray dog down the right path.

Thanks in advance.