Hi,
I have a MySQL table that has columns from other tables, and im trying to populate it using PHP (no luck). The table has three columns from other tables, and a user supplied column.
So far i am able to get the column titles from the database, and the column entries, but i have tried so many ways no luck. The best i have managed so far is to insert just one row, with fixed values, the first contaminant, and the last sample :S. Any hints/help/support will be greatly appreaciated - i’ve been on this for way too long!
Here is the form:
<?php
include("database.php");
// Error reporting
//error_reporting (E_ALL ^ E_NOTICE);
$query = "SELECT contaminant, gac_value, sample_name
FROM gac_ea, sample
WHERE land_use = 'Allotment'
AND sample.site_id = 1
ORDER BY sample.id ";
$result = mysql_query($query) or die(mysql_error());
while ($row = mysql_fetch_array($result)) {
extract($row); }
?>
<br><br>
<form name="gqra" id="gqra" action="insert_gqra.php" method="POST">
<table class="qra">
<tr>
<td class="row2" > </td>
<?php
$query = "SELECT site.id, sample_name
FROM site, sample, prelim
WHERE site.id = 1
AND sample.site_id = site.id
AND prelim.site_id = site.id
ORDER BY sample.id ASC LIMIT 5";
$result = mysql_query($query) or die(mysql_error());
while ($row = mysql_fetch_array($result)) {
extract($row);
echo "<td class=\\"row2\\" ><label> <span> $sample_name</span> </label></td> " ; }
echo "</tr>"; //close row
?>
<tr>
<td class="row3">
<?php
$query3 = "SELECT contaminant, gac_value FROM gac_ea WHERE land_use = 'Allotment' ORDER BY id";
$result3 = mysql_query($query3) or die(mysql_error());
echo "<select name=contaminant value=''></option>";
echo "<option>Select </option>";
while($row=mysql_fetch_array($result3)){
extract($row);
echo "<br>".$contaminant;
echo "<option value=$row[id]>$row[contaminant]</option>"; } // End contaminant loop
echo "</select>"; ?>
</td>
<td class="row3"><input type="text3" name="ms_conc" id="ms_conc" /></td>
<td class="row3"><input type="text3" name="ms_conc" id="ms_conc" /></td>
<td class="row3"><input type="text3" name="ms_conc" id="ms_conc" /></td>
<td class="row3"><input type="text3" name="ms_conc" id="ms_conc" /></td>
<td class="row3"><input type="text3" name="ms_conc" id="ms_conc" /></td>
</tr>
</tr>
<tr>
<td class="row3">
<?php
$query3 = "SELECT contaminant, gac_value FROM gac_ea WHERE land_use = 'Allotment' ORDER BY id";
$result3 = mysql_query($query3) or die(mysql_error());
echo "<select name=contaminant value=''></option>";
echo "<option>Select </option>";
while($row=mysql_fetch_array($result3)){
extract($row);
echo "<br>".$contaminant;
echo "<option value=$row[id]>$row[contaminant]</option>"; } // End contaminant loop
echo "</select>"; ?>
</td>
<td class="row3"><input type="text3" name="ms_conc" id="ms_conc" /></td>
<td class="row3"><input type="text3" name="ms_conc" id="ms_conc" /></td>
<td class="row3"><input type="text3" name="ms_conc" id="ms_conc" /></td>
<td class="row3"><input type="text3" name="ms_conc" id="ms_conc" /></td>
<td class="row3"><input type="text3" name="ms_conc" id="ms_conc" /></td>
</tr>
</tr>
<tr>
<td class="row3">
<?php
$query3 = "SELECT contaminant, gac_value FROM gac_ea WHERE land_use = 'Allotment' ORDER BY id";
$result3 = mysql_query($query3) or die(mysql_error());
echo "<select name=contaminant value=''></option>";
echo "<option>Select </option>";
while($row=mysql_fetch_array($result3)){
extract($row);
echo "<br>".$contaminant;
echo "<option value=$row[id]>$row[contaminant]</option>"; } // End contaminant loop
echo "</select>"; ?>
</td>
<td class="row3"><input type="text3" name="ms_conc" id="ms_conc" /></td>
<td class="row3"><input type="text3" name="ms_conc" id="ms_conc" /></td>
<td class="row3"><input type="text3" name="ms_conc" id="ms_conc" /></td>
<td class="row3"><input type="text3" name="ms_conc" id="ms_conc" /></td>
<td class="row3"><input type="text3" name="ms_conc" id="ms_conc" /></td>
</tr>
</tr>
<tr>
<td colspan="6" class="button" >
<input type="reset" value="Clear input" />
<input type="submit" value="Compare with SGVs" /></td>
</tr>
</table>
</form>
And the insert script:
<?php
// $cont_name = $_POST['cont_name'];
// $sample_name = $_POST['sample_name'];
// $gac_value = $_POST['gac_value'];
$ms_conc = $_POST['ms_conc'];
$query = "INSERT INTO qgra (id, contaminant, sample_name, gac_value, ms_conc)
VALUES ('','$contaminant', '$sample_name', '$gac_value', '$ms_conc')";
$result = mysql_query($query) or die(mysql_error());
echo "<br><br> Gac saved! ";
?>
I’m thing the insert script should be something like:
for each sample and selected contaminant, insert sample, contaminant, gac_value from the database and the user inputs (ms_conc). I have tried doing that but it didnt work either.