Jump to content

Problem with Radio buttons in sub loop


JAM14
Go to solution Solved by JAM14,

Recommended Posts

Hi. I'm having a problem regarding my codes involving radio buttons and subloop. I couldn't retrieve the data from post and I can't insert them to the database. I just couldn't find the error.

 

Here's my form's code:

<form method="post">

<?php 
	
$select_paragraph=mysql_query('SELECT * FROM dependency');
$questrows = 0;
while($get_paragraph = mysql_fetch_array($select_paragraph))
{
	$TestID = $get_paragraph['testId'];
	$Dependid = $get_paragraph['DependencyId'];
			
	echo"
		<table border='1'>
			<tr class='classheader1'>
				<td align='center' class='paragraph'>". $get_paragraph['Situation']. "</td>				
					<table>";
						$select_question=mysql_query('SELECT * FROM dependentitems where DependencyId="'.$Dependid.'"');
						while($get_question = mysql_fetch_array($select_question))
						{
							echo $LitId = $get_question['LiteralId'];
							echo $ItemID = $get_question['ItemId'];
							
							echo"
								<tr><td align='left' class='paragraph'><br>". $get_question['Question']. "</td></tr>
								<tr><td align='left' class='paragraph'><input type='radio' name='Option".$questrows."' value = '". $get_question['Option1']. "'>". $get_question['Option1']. "</td></tr>
								<tr><td align='left' class='paragraph'><input type='radio' name='Option".$questrows."' value = '". $get_question['Option2']. "'>". $get_question['Option2']. "</td></tr>
								<tr><td align='left' class='paragraph'><input type='radio' name='Option".$questrows."' value = '". $get_question['Option3']. "'>". $get_question['Option3']. "</td></tr>
								<tr><td align='left' class='paragraph'><input type='radio' name='Option".$questrows."' value = '". $get_question['Option4']. "'>". $get_question['Option4']. "</td></tr>
							";
							echo "Radio Names = Option".$questrows." ";
							$questrows++;
						}	
						echo"
					</table>
				</td>
			</tr>
		</table>
	";
}
?>

<input type="submit" name="enter" value="Submit"/>
</form>

And here's the code where I retrieve the post so I could insert them into my database:

<?php
if(@$_POST['enter'])
{
	$select_paragraph=mysql_query('SELECT * FROM dependency');
	$questrows = 0;
	while($get_paragraph = mysql_fetch_array($select_paragraph))
	{
		$TestID = $get_paragraph['testId'];
		$Dependid = $get_paragraph['DependencyId'];
		$select_question=mysql_query('SELECT * FROM dependentitems where DependencyId="'.$Dependid.'"');
	
		while($get_question = mysql_fetch_array($select_question))
		{
			echo "Hi".@$option=$_POST['Option'.$questrows];
			echo "<br>LitId = ".$LitId = $get_question['LiteralId'];
			echo "<br>ItemId = ".$ItemID = $get_question['ItemId'];
			echo '<br>ThisOption'.$questrows;
			$insertToTemp="insert into temp(StudId, TestId, ItemId, LiteralId, Choice) values(1, 3,  $ItemID,$LitId,'$option[$questrows]')";
			mysql_query($insertToTemp);
			$questrows++;	
			echo "<br>";
		}	
	}
}
?>

Hope you could help me find the error. Thanks.

Link to comment
Share on other sites

  • Solution

I've worked on this the entire night. Finally, after two weeks, I came up with these codes:

<?php

if(@$_POST['submit'])
{
$select_paragraph=mysql_query('SELECT * FROM dependency');
$questrows = 0;
while(mysql_fetch_array($select_paragraph))
{
$counter = 0;
$select_question=mysql_query('SELECT * FROM dependentitems where DependencyId="'.$Dependid.'"');
$rows = mysql_num_rows($select_question);
while($counter < $rows){
echo "<br>";
@$b=$_POST['Option'.$questrows];
$s="insert into temp(StudId, TestId, ItemId, LiteralId, Choice) values(1, 3,  $questrows,'','$b')";
mysql_query($s);
$counter++;
$questrows++;
}
}
header("Location: validate.php");
}

?>

It solved my problem. @blacknight: Thanks anyway for the help.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.