I've got a form like so:
Question: <input type="text" name="question[][text]" id="question" />
Type:
<select name="question[][type]" id="type">
<option value="1to5scale">1 to 5 scale</option>
<option value="freetext">Open text</option>
</select>
This gets repeated depending on how many items the user wants (cloned through jquery). And my php to action the form contains:
foreach ( $_POST['question'] as $key=>$question )
{
if ($key >= 1) {
$question_text = $question['text'];
$type = $question['type'];
$query = " INSERT INTO questions (question_text, survey_id, type) ".
" VALUES ('$question_text','$survey_id', '$type')";
mysql_query($query) or die('Error ,query failed');
}
}
Each question has a text item and a type item. However in the DB it's adding one row per question item (if that makes sense...), rather than one row per complete question. Any ideas where I'm going wrong, it's quite hard to debug forms I'm finding...