I have a simple form with a pull down menu that is populated from my database. This work. Here's my code:
...
<form method=post action="checkin_entry.php">
<?php
$query = "select * from people ORDER BY lname";
$result = mysql_query($query);
echo '<select name="person_ID">';
echo '<option value="" selected>Select Name</option>';
/*Dynamically generate drop-down list*/
while ($row=mysql_fetch_array($result)) {
$id = $row['person_ID'];
$lname = $row['lname'];
$fname = $row['fname'];
echo "<option value='$id'>$lname, $fname</option>";
}
echo '</select><p>';
?>
<!-- Date_ID is manually entered -->
<table>
<tr>
<td><b>date_ID</b></td>
<td><input type=text size=40 name=date_ID></td>
</tr>
</table>
<input type=submit name=submit value="Submit">
<input type=reset name=reset value="Clear">
</form>
...
The next page (checkin_entry.php) will post my data to my database (to attendance table); however, I also want it to retrieve the person's name from the database (from people table) by using the person_ID that was choosen in the form. I want it to say "FNAME LNAME has been successfully entered". What am I doing wrong? It's not retrieving the first and last name from the people table?
Here's the code for checkin_entry.php:
...
<?php
if ($submit == "Submit") {
$sql = "INSERT into attendance (person_ID, date_ID) VALUES ('$person_ID', '$date_ID') ";
mysql_query($sql) or die ("Unable to post information to database.");
?>
<?php
// Retrieve data from the selected table
$result = mysql_query("SELECT * FROM people WHERE person_ID=".$_GET['person_ID']) or die (mysql_error());
// store the data of the selected table into $row
$row = mysql_fetch_array( $result );
// Print out the contents of the entry
echo "First: ".$row['fname'];
echo "<br>";
echo "Last: ".$row['lname'];
?>
<?php
}
?>
...
I would appreciate you comments. Thanks for you help in advance.