Hi,
I am very new to php so feel free to have a giggle at my code. I am trying to populate a table with data after an option has been selected form a drop down menu in a form. My problem comes from the fact that the drop down options are generated from the data, or I’m just being really stupid.
here is a snippet
[code]<?php
include 'includes/connection.php';
$query = ("SELECT * FROM COSHH") or die ('Error: '.mysql_error ());
$result = mysql_query($query);
while($substance = mysql_fetch_array($result, MYSQLI_ASSOC)) {
echo "<form action'result.php' name='Substance_choice' method='post'>Please choose a Substance<br/><br/>
<select name='substance_dropdown'>
<option value='" . $substance['substance_name'] . "'>" . $substance['substance_name'] .
"</option>";
}
echo “”
?>
Results
<?php if (isset($_POST['submitted'])) {include(‘includes/connection.php’);
$subname = $_POST[’$substance’];
$substance_dropdown = $_POST[‘substance_dropdown’];
$query = “SELECT * FROM COSHH WHERE substance_dropdown=’$subname’”;
$result = mysqli_query($dbcon, $query) or die(‘error getting data’);
echo “
ID | Name | Age |
---|