Annuscha 0 Newbie Poster

Hi,

I have a problem getting the value of my arrays into my database.

I have 2 sections, the thing is the first section adds all the correct values into the database, where the second section adds 0 to the question_id variable.

Form Page:

//Section 1
							
$countquestion = 0;
$query = "SELECT uid, question FROM evaluation_phase2 WHERE client_uid_fk = '$client' AND section = '1'";
$result = mysql_db_query($dbName,$query,$connect);

while ($row = mysql_fetch_assoc($result)) {
$countquestion++;
?>

<tr style="border-bottom: 1px solid #c3c3c3;">
<td colspan="2" width="400px" bgcolor="#f8f7f7" style="border-left: 1px solid #c3c3c3; border-right: 1px solid #c3c3c3; border-top: 1px solid #c3c3c3; border-bottom: 1px solid #c3c3c3;" class="style8"><?php echo $row['question']?>
<input type="hidden" name="question_id[<?php echo $row['uid']?>]" value="<?php echo $row['uid']?>" /></td>

<td style="border-right: 1px solid #c3c3c3; border-top: 1px solid #c3c3c3; font-weight: bold;" bgcolor="#f8f7f7" width="30px">1<input type="radio" name="answer[<?php echo $countquestion?>]" value="1" /></td>

<td style="border-right: 1px solid #c3c3c3; border-top: 1px solid #c3c3c3; border-bottom: 1px solid #c3c3c3; font-weight: bold;" bgcolor="#f8f7f7" width="30px">2<input type="radio" name="answer[<?php echo $countquestion?>]" value="2" /></td>

<td style="border-right: 1px solid #c3c3c3; border-top: 1px solid #c3c3c3; border-bottom: 1px solid #c3c3c3; font-weight: bold;" bgcolor="#f8f7f7" width="30px">3<input type="radio"
name="answer[<?php echo $countquestion?>]" value="3" /></td>

<td style="border-right: 1px solid #c3c3c3; border-top: 1px solid #c3c3c3; border-bottom: 1px solid #c3c3c3; font-weight: bold;" bgcolor="#f8f7f7" width="30px">4<input type="radio" name="answer[<?php echo $countquestion?>]" value="4" /></td>

<td style="border-right: 1px solid #c3c3c3; border-top: 1px solid #c3c3c3; border-bottom: 1px solid #c3c3c3; font-weight: bold;" bgcolor="#f8f7f7" width="30px">5<input type="radio" name="answer[<?php echo $countquestion?>]" value="5" /></td>

<td style="border-right: 1px solid #c3c3c3; border-top: 1px solid #c3c3c3; border-bottom: 1px solid #c3c3c3;" bgcolor="#f8f7f7"><textarea id="label" rows="1" cols="15" name="comment[<?php echo $row['uid']?>]"></textarea></td>
</tr>

<?php }?>
							
<tr><td bgcolor="#d4d2d2" class="style6"  colspan="8" style="border-top: 1px solid #c3c3c3; border-left: 1px solid #c3c3c3; border-right: 1px solid #c3c3c3; border-bottom: 1px solid #c3c3c3;">Overcoming Objections</td></tr>

<?php
							
//Section 2
							
$countquestion2 = 0;
$query2 = "SELECT uid, question FROM evaluation_phase2 WHERE client_uid_fk = '$client' AND section = '2'";
$result2 = mysql_db_query($dbName,$query2,$connect);

while ($row2 = mysql_fetch_assoc($result2)) {
$countquestion2++;
?>

<tr style="border-bottom: 1px solid #c3c3c3;">
<td colspan="2" width="400px" bgcolor="#f8f7f7" style="border-left: 1px solid #c3c3c3; border-right: 1px solid #c3c3c3; border-top: 1px solid #c3c3c3; border-bottom: 1px solid #c3c3c3;" class="style8"><input type="hidden" name="question_id2[<?php echo $row2['uid']?>]" value="<?php echo $row2['uid']?>" /><?php echo $row2['question']?></td>

<td style="border-right: 1px solid #c3c3c3; border-top: 1px solid #c3c3c3; font-weight: bold;"
bgcolor="#f8f7f7" width="30px">1<input type="radio" name="answer2[<?php echo $countquestion2?>]" value="1" /></td>

<td style="border-right: 1px solid #c3c3c3; border-top: 1px solid #c3c3c3; border-bottom: 1px solid #c3c3c3; font-weight: bold;" bgcolor="#f8f7f7" width="30px">2<input type="radio" name="answer2[<?php echo $countquestion2?>]" value="2" /></td>
								
<td style="border-right: 1px solid #c3c3c3; border-top: 1px solid #c3c3c3; border-bottom: 1px solid #c3c3c3; font-weight: bold;" bgcolor="#f8f7f7" width="30px">3<input type="radio" name="answer2[<?php echo $countquestion2?>]" value="3" /></td>
								
<td style="border-right: 1px solid #c3c3c3; border-top: 1px solid #c3c3c3; border-bottom: 1px solid #c3c3c3; font-weight: bold;" bgcolor="#f8f7f7" width="30px">4<input type="radio"
name="answer2[<?php echo $countquestion2?>]" value="4" /></td>
								
<td style="border-right: 1px solid #c3c3c3; border-top: 1px solid #c3c3c3; border-bottom: 1px solid #c3c3c3; font-weight: bold;" bgcolor="#f8f7f7" width="30px">5<input type="radio"
name="answer2[<?php echo $countquestion2?>]" value="5" /></td>
		
<td style="border-right: 1px solid #c3c3c3; border-top: 1px solid #c3c3c3; border-bottom: 1px solid #c3c3c3;" bgcolor="#f8f7f7"><textarea id="label" rows="1" cols="15" name="comment2[<?php echo $row2['uid']?>]"></textarea></td>
</tr>
<?php }?>

Submit Page:

//Section 1

	$sql_data = array();
	$sql_prefix = "INSERT INTO agents_phase2(client_uid_fk, team_leaders_uid_fk, agent_uid_fk, question_id, question_answer, section, evaluation_number) VALUES";
	foreach($_POST['answer'] as $id => $answer){
		$client_id = (int) $_POST['client_id'];
		$team_leader_id = (int) $_POST['team_leader_id'];
		$agent_id  = (int) $_POST['agent_id'];
		$question_id  = (int) $_POST['question_id'][$id];
		$answer      = (int)($answer);

		$sql_data[] = "($client_id, $team_leader_id, $agent_id, $question_id, '$answer', '1', '1')";

		$sql = $sql_prefix.implode(", \n", $sql_data);
	}

	mysql_db_query($dbName, $sql, $connect);

	//Section 2

	$sql_data2 = array();
	$sql_prefix2 = "INSERT INTO agents_phase2(client_uid_fk, team_leaders_uid_fk, agent_uid_fk, question_id, question_answer, section, evaluation_number) VALUES";
	foreach($_POST['answer2'] as $id2 => $answer2){
		$client_id2 = (int) $_POST['client_id'];
		$team_leader_id2 = (int) $_POST['team_leader_id'];
		$agent_id2  = (int) $_POST['agent_id'];
		$question_id2  = (int) $_POST['question_id2'][$id2]; // My problem is it add 0 to the database where it should add the id of the question all the other variables has the correct values.
		$answer2      = (int)($answer2);
		print_r($_POST);
		$sql_data2[] = "($client_id2, $team_leader_id2, $agent_id2, $question_id2, '$answer2', '2', '1')";

		$sql2 = $sql_prefix2.implode(", \n", $sql_data2);
	}

	mysql_db_query($dbName, $sql2, $connect);

Can someone please tell me what I'm doing wrong.

Thanks