garian_of_brunlea Posted February 24, 2007 Share Posted February 24, 2007 Hiya I have 3 tables Campaign campID camp Questions questID campID quest Answers ansID questID answer Once someone select the campaign it displays all the questions and asnwers as multiple choice radio box. It then displays a form that has Question All the answers with radio box to select I post these to a process page where i need to add campID, questID and ansID to a results table. I have it so the results pull out everything but the questID. The process page is below the form i use to display the questions. Also, I can get the results to print but when i try to insert them, i get an error. ====================================================================== <form id="form1" name="form1" method="post" action="process.php"> <?php if ($totalRows_rsQuest > 0) { // Show if recordset not empty ?><table width="700" border="0" cellspacing="0" cellpadding="0"> <?php do { $quest=$row_rsQuest['questID']; mysql_select_db($database_camp, $camp); $query_rsAns = "SELECT * FROM answer WHERE questID = $quest"; $rsAns = mysql_query($query_rsAns, $camp) or die(mysql_error()); $row_rsAns = mysql_fetch_assoc($rsAns); $totalRows_rsAns = mysql_num_rows($rsAns); ?> <tr> <td bgcolor="#EFEFEF"><strong><?php echo $row_rsQuest['questID']; ?></strong> <?php echo $row_rsQuest['question']; ?> <br> <br> <table width="700" border="0" cellspacing="0" cellpadding="0"> <?php do { ?> <tr> <td bgcolor="#FFFFFF"><label> <input name="box1[]" type="checkbox" id="box1[]" value="<?php echo $row_rsAns['ansID']; ?>" /> </label> <?php echo $row_rsAns['answer']; ?> <input name="questID" type="hidden" id="questID" value="<?php echo $row_rsAns['questID']; ?>" /> <input name="campID" type="hidden" id="campID" value="<?php echo $row_rsQuest['campID']; ?>" /> <input name="ansID" type="hidden" id="ansID" value="<?php echo $row_rsAns['ansID']; ?>" /></td> </tr> <?php } while ($row_rsAns = mysql_fetch_assoc($rsAns)); ?> </table></td> </tr> <tr> <td><hr size="1" noshade="noshade" /></td> </tr> <?php } while ($row_rsQuest = mysql_fetch_assoc($rsQuest)); ?> <tr> <td></td> </tr> </table><?php } // Show if recordset not empty ?><input name="Submit" type="submit" value="Submit" /> </form> Process page <?php require_once('Connections/camp.php'); // $camp=$_POST['campID']; $box=$_POST['box1']; $ans=$_POST['ansID']; $questID=$_POST['questID']; foreach ($box as $answer){ //testing results echo "campaign ".$camp."<br>"; echo "Question ".$questID."<br>"; echo "answerID ".$answer."<br>"; echo "<br><br>"; //mysql_select_db($database_camp, $camp); //$query_RersRes = "INSERT into results (campID, questID, ansID) VALUES ('$questID', '$camp', '$answer')"; //$RrsRes = mysql_query($query_RrsRes, $camp) or die(mysql_error()); } //header("Location: success.php"); ?> Link to comment https://forums.phpfreaks.com/topic/39939-inserting-records-based-on-two-recordsets-and-array/ Share on other sites More sharing options...
paul2463 Posted February 24, 2007 Share Posted February 24, 2007 you probably get the errors because of this part here $camp=$_POST['campID']; //i take it this is not a connections script??? mysql_select_db($database_camp, $camp); $query_RersRes = "INSERT into results (campID, questID, ansID) VALUES ('$questID', '$camp', '$answer')"; $RrsRes = mysql_query($query_RrsRes, $camp) or die(mysql_error()); i think you have got the connections script require_once('Connections/camp.php'); mixed up with the variable you have set above mysql_select() and mysql_query() do not need another argument that is a variable and not a connection to work with try this mysql_select_db($database_camp); $query_RersRes = "INSERT into results (campID, questID, ansID) VALUES ('$questID', '$camp', '$answer')"; mysql_query($query_RrsRes) or die(mysql_error()); Link to comment https://forums.phpfreaks.com/topic/39939-inserting-records-based-on-two-recordsets-and-array/#findComment-193035 Share on other sites More sharing options...
garian_of_brunlea Posted February 25, 2007 Author Share Posted February 25, 2007 I tried that but get an error "query is empty" $camp=$_POST['campID']; was not a connection string, ity just grabs the campID from the form. Here is the new code. <?php require_once('Connections/camp.php'); // $camp=$_POST['campID']; $box=$_POST['box1']; $ans=$_POST['ansID']; foreach ($box as $answer){ $split = explode(",", $answer); $answ = $split[0]; $quest = $split[1]; echo "campaign ".$camp."<br>"; echo "Question ".$quest."<br>"; echo "answerID ".$answ."<br>"; echo "<br><br>"; mysql_select_db($database_camp); $query_RersRes = "INSERT into results (campID, questID, ansID) VALUES ('$camp', '$quest', '$answ')"; mysql_query($query_RrsRes) or die(mysql_error()); } header("Location: success.php"); ?> Link to comment https://forums.phpfreaks.com/topic/39939-inserting-records-based-on-two-recordsets-and-array/#findComment-193705 Share on other sites More sharing options...
paul2463 Posted February 25, 2007 Share Posted February 25, 2007 What I suggest now is for you to echo out the query and see if it makes sense instead of $query_RersRes = "INSERT into results (campID, questID, ansID) VALUES ('$camp', '$quest', '$answ')"; put echo "INSERT into results (campID, questID, ansID) VALUES ('$camp', '$quest', '$answ')"; you will see what the query is that the system is trying to run, strange to get an "empty Query" from an insert statement. Link to comment https://forums.phpfreaks.com/topic/39939-inserting-records-based-on-two-recordsets-and-array/#findComment-193878 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.