Hi,

I am trying to insert two columns each from a different table into a single table and give that a value and i can only find insert INTO different table examples, and none for FROM different tables?

I have attached the table im trying to insert into: the samples, and the selection have been populated from the database. What im trying to do is for each sample and each selection (matrix) insert a value into the database using the form.

I'm thinking the problem is assigning a (sample, selection) value to each box? The column i want to save the values in the databse is called ms_conc, thats why i have assigned all the text areas the same value. Here are three lines from the form. A bit long, sorry:

<form > 
<table >
  <tr>
    <td >&nbsp;</td>
    <?php
   $query = "SELECT site.id, sample_name
			 FROM site, sample, prelim
			 WHERE site.id = '$id'
			 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> " ; 

} ?>
  </tr>
  <tr>
    <td ><?php 
	$query = "SELECT contam, gac_value FROM gac_ea WHERE land_use = '$l_euse' ORDER BY id";
	$result = mysql_query($query) or die(mysql_error());
	
	echo "<select name=contam value=''></option>";
	echo "<option>Select </option>";
	while($row=mysql_fetch_array($result)){ 	
		echo "<option value=$row[id]>$row[contam]</option>";}
		echo "</select>"; ?></td>
    <td ><input type="text3" name="ms_conc" id="ms_conc" /></td>
    <td ><input type="text3" name="ms_conc" id="ms_conc" /></td>
    <td ><input type="text3" name="ms_conc" id="ms_conc" /></td>
    <td ><input type="text3" name="ms_conc" id="ms_conc" /></td>
    <td ><input type="text3" name="ms_conc" id="ms_conc" /></td>
  </tr>
  <tr>
    <td></tr></td>
  </tr>
  <tr>
    <td ><?php 
	$query = "SELECT contam, gac_value FROM gac_ea WHERE land_use = '$l_euse' ORDER BY id";
	$result = mysql_query($query) or die(mysql_error());  
	
	echo "<select name=contam value=''></option>";
	echo "<option>Select </option>";
	while($row=mysql_fetch_array($result)){ 	
		echo "<option value=$row[id]>$row[contam]</option>";}
		echo "</select>"; ?></td>
    <td ><input type="text3" name="ms_conc" id="ms_conc" /></td>
    <td ><input type="text3" name="ms_conc" id="ms_conc" /></td>
    <td ><input type="text3" name="ms_conc" id="ms_conc" /></td>
    <td ><input type="text3" name="ms_conc" id="ms_conc" /></td>
    <td ><input type="text3" name="ms_conc" id="ms_conc" /></td>
  </tr>
  <tr>
    <td></tr></td>
  </tr>
  <tr>
    <td ><?php 
		$query = "SELECT contam, gac_value FROM gac_ea WHERE land_use = '$l_euse' ORDER BY id";
	$result = mysql_query($query) or die(mysql_error()); 
	
	echo "<select name=contam value=''></option>";
	echo "<option>Select </option>";
	while($row=mysql_fetch_array($result)){ 	
		echo "<option value=$row[id]>$row[contam]</option>";}
		echo "</select>"; ?></td>
    <td ><input type="text3" name="ms_conc" id="ms_conc" /></td>
    <td ><input type="text3" name="ms_conc" id="ms_conc" /></td>
    <td ><input type="text3" name="ms_conc" id="ms_conc" /></td>
    <td ><input type="text3" name="ms_conc" id="ms_conc" /></td>
    <td ><input type="text3" name="ms_conc" id="ms_conc" /></td>
  </tr>
</table>

</form>

Recommended Answers

All 2 Replies

I see this multiple times:

echo "<option value=$row[id]>$row[contam]</option>";

However, NONE of your SELECT statements are "asking" for the column `id`, so $row[id] is empty and you would NOT see a value for your elements when the form is posted.

If your table does have an `id` column, be sure to SELECT it as well: SELECT id, contam, gac_value ...

Thanks - will work on it, Still a giant headache.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.