HI, I'm new to PHP/MySQL and having trouble with this. I'd like to select data from my database, use that data to populate a form, and then submit the form based on the user's selection.
The problem I'm running into is that the form always submits the values of $studio_id and $name as they are when they exit the while loop, instead of using the values of what's been selected.
How can I set this up so that the form action changes depending on the user's selection? Thanks in advance.
The problem I'm running into is that the form always submits the values of $studio_id and $name as they are when they exit the while loop, instead of using the values of what's been selected.
How can I set this up so that the form action changes depending on the user's selection? Thanks in advance.
Code:
<?php
error_reporting(E_ALL);
$studio_id = $_GET['studio_id'];
$name = $_GET['name'];
if (isset($name)) {
$includeForm = 1;
}
?>
<form method="post" action="add_class2.php?studio_id=<?php echo $studio_id; ?>&name=<?php echo $name; ?>">
<select>
<?php
//connect to db
include('config.php');
// Query if the user has entered an explicit time
$query = "SELECT *
FROM studios
ORDER BY name ASC";
// Retrieve all the data from the example table
$result = mysql_query($query) or die(mysql_error());
// Create loop to fill the form
while ($row = mysql_fetch_array($result)) {
$studio_id = $row['studio_id'];
$name = $row['name'];
echo "<option value=\"add_class.php?studio_id=$studio_id&name=$name\">$name";
}
?>
</select>
<input type="submit" value="Go" />
</form>
<?php
if (isset($includeForm)) {
//Display the class submission form
include('class_form.php');
} else {
include('test_footer1.php');
}
?>
Comment