Hey all,

I am trying to insert some items into a mysql database but am having some issues. (no this isnt totally a mysql question) =p I have a dynamic form that is being generated where I need the data from that form inserted into the mysql database. The form will vary depending on what the user wants out of it.. it may have a varying number of columns and rows with each intersection making a text field.. just like excel. I am trying to get the headers to insert and have it just loop through the headers and add a new header each time into the database. Right now I am just trying to get two headers to show up.. header_top1 and 2. if I do a standard insert without the "for" loop, then the insert works, but only inserts the last header name entered. if I run it as you see below, then I can print this and see everything showing up correctly, but nothing inserts at all. Any ideas? Thanks!

		$tmpquery1 = "INSERT INTO ".$tableName["tctable"]."(name,added_by,header_top1,header_top2) VALUES('$name','$added_by')";

	for($k = 0; $k < count($header_top); )
{			
		$header_topA = $header_top[$k];
		$tmpquery1 .= ",'$header_topA'";
		 $k++;
}	

	$tmpquery1 .= ")";

    I figured out why it wont insert, so I guess now I need to know if there is a way around this. The problem lies in the fact that the header specifications and the values dont always match up in that their may be 20 header specifications and only 18 values (if the form is created smaller than the 20 headers).. Is there any way to have it still insert, just up to the 18 mark instead of not doing any insert if it doesnt hit 20?

      Write a Reply...