dapcigar Posted September 9, 2015 Share Posted September 9, 2015 Am trying to save the result of the the selected answer with the question id. don't know how to pass the id to the DB. here's my code <?php session_start(); include('config/manpower_db.php'); $sql = mysql_query("SELECT * FROM question") or die(mysql_error()); $i = '1'; ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>Untitled Document</title> </head> <body> <form action="save_feedback2.php" method="post"> <H2> How Will You Rate This Service</H2> <?php while($row = mysql_fetch_array($sql)) { echo $row['question']; $comp = $row['id'][$i]; // $_SESSION['comp']= $comp; ?> <br /> <?php echo "<td> <input type='radio' name='answer[".$row['id']."]' value='1' >1"; echo "<td> <input type='radio' name='answer[".$row['id']."]' value='2' >2"; echo "<td> <input type='radio' name='answer[".$row['id']."]' value='3' >3"; echo "<td> <input type='radio' name='answer[".$row['id']."]' value='4' >4"; echo "<td> <input type='radio' name='answer[".$row['id']."]' value='5' >5"; echo "<input type='hidden' name='question_id' value=$comp >"; echo'<br/>'; $i++; } ?> <br/> <strong> NOTE:</strong> 1 - Very Poor, 2 - poor, 3 - Okay, 4 - Fair, 5 - Good <p> <input name="submit" type="submit" value="submit" /> </form> </body> </html> Save to DB <?php session_start(); $answer = $_POST['answer']; $hobb = $_POST['question_id']; include('config/manpower_db.php'); foreach($hobb as $key=>$val) { $var1=$hobb[$key]; $var2=$answer[$key]; //include ('connect.php'); //include ('mysql_connect.php'); $table = "INSERT INTO answer (question_id,answer) ". "VALUES ('$var2','$var2')"; mysql_query($table) or die(mysql_error()); $inserted_fid = mysql_insert_id(); mysql_close(); } echo'<script>alert("Inserted Successfully")</script>'; ?> Please HELP!! thanks in advance Quote Link to comment Share on other sites More sharing options...
Barand Posted September 9, 2015 Share Posted September 9, 2015 see http://forums.phpfreaks.com/topic/298080-quiz-results-passing-displaying-wrong/?do=findComment&comment=1520505 Quote Link to comment 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.