Hi there
I'm new to php and MySQL and I'm busy trying to build a page that when the administrator selects an item from a drop-down list, that has been populated from a database, it populates multiple text fields with the appropriate information from the database. For example, if the administrator selects "Flower Show" from the selection box then the text fields Heading, Date and Details get populated with "Flower Show", date of the flower show, and a description of the flower show.
Here is what I have so far:
<form name="events" method="post" action="<?= $_SERVER['PHP_SELF']?>">
<table>
<tr>
<td> </td>
<td>
<?php
// open connection to MySQL server
$connection = mysql_connect('localhost', 'username', 'password')
or die ('Unable to connect!');
//select database
mysql_select_db('test') or die ('Unable to select database!');
//create and execute query
$query = 'SELECT DISTINCT heading FROM events ORDER BY heading';
$result = mysql_query($query) or die ('Error in query: $query. ' . mysql_error());
//create selection list
echo "<select name='Events'>\n";
while($row = mysql_fetch_row($result))
{
$heading = $row[0];
echo "<option value='$heading'>$heading\n";
}
echo "</select>"
?>
</td>
</tr>
<tr>
<td align="right" valign="top"><p>Heading:</p></td>
<td>
<input type="text" name="eventHeading" id="eventHeading" class="heading">
</td>
</tr>
<tr>
<td align="right" valign="top"><p>Date:</p></td>
<td>
<input type="text" name="eventDate" id="eventDate" class="date">
</td>
</tr>
<tr>
<td align="right" valign="top"><p>Details:</p></td>
<td>
<textarea name="eventDetails" id="eventDetails" class="details"></textarea>
</td>
</tr>
<tr>
<td> </td>
<td>
<input name="submit" type="submit" class="submitForm" value="Submit">
</td>
</tr>
</table>
</form>
Any help will be greatly appreciated. Been searching the web endlessly for a solution.