JAM14 Posted April 28, 2013 Share Posted April 28, 2013 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. Quote Link to comment https://forums.phpfreaks.com/topic/277396-problem-with-radio-buttons-in-sub-loop/ Share on other sites More sharing options...
blacknight Posted April 29, 2013 Share Posted April 29, 2013 @$_POST['enter'] is suppressing your errors remove the @ and run it again also try printing the post info and see whats being sent using print_r(); Quote Link to comment https://forums.phpfreaks.com/topic/277396-problem-with-radio-buttons-in-sub-loop/#findComment-1427087 Share on other sites More sharing options...
Solution JAM14 Posted April 30, 2013 Author Solution Share Posted April 30, 2013 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. Quote Link to comment https://forums.phpfreaks.com/topic/277396-problem-with-radio-buttons-in-sub-loop/#findComment-1427246 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.