Note that there are some explanatory texts on larger screens.

plurals
  1. POsave random data to db without duplication - php
    text
    copied!<p>It is an examination system and I made a random question, my problem is how to save it and identify if it is already saved in the database.<br> Below is the code for the random, why after I click the next even it doesn't have an action in the FORM it post undefined index "sub" BUT i already declare it at the top. How to save data, if it is random and avoid to duplicate the saved data?</p> <pre><code>&lt;? $exam_id = $_SESSION['examreference_id']; $sub_id = $_GET['sub']; $count=0; $con = mysql_connect("localhost","root",""); if(!$con) { die('Could not connect:'. mysql_error()); } mysql_select_db("db_compre",$con); $result2 = mysql_query("SELECT * FROM examquestion_table WHERE examreference_id = '$exam_id' AND subjectreference_id = '$sub_id'"); while($info2 = mysql_fetch_array($result2)) { $count++; } mysql_close($con);?&gt; &lt;tr&gt; &lt;td colspan = "2"&gt; &lt;? $con = mysql_connect("localhost","root",""); if(!$con) { die('Could not connect:'. mysql_error()); } mysql_select_db("db_compre",$con); $result = mysql_query("SELECT * FROM examquestion_table WHERE examreference_id = '$exam_id' AND subjectreference_id = '$sub_id' ORDER BY RAND() LIMIT 1"); while($info = mysql_fetch_array($result)) { echo "&lt;tr&gt;&lt;td &gt;&lt;label&gt;" . " Your time limit is ".$info['totalTime'] ."&amp;nbsp&amp;nbsp". "second(s)" . "&lt;/label&gt;&lt;/td&gt;&lt;/tr&gt;"; echo "&lt;tr&gt;&lt;td &gt;&lt;label&gt;" . $info['question_data'] . "&lt;/label&gt;&lt;/td&gt;&lt;/tr&gt;"; echo "&lt;tr&gt;&lt;td colspan ='2'&gt;&lt;hr size = '5' color = 'orange'&gt;&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;"; echo "&lt;tr&gt;&lt;td colspan = '2'&gt;&lt;input type = 'checkbox' name='answer' onClick='javascript:checkone(0)' value = '100'&gt;&lt;label&gt;". $info['choice1_data'] ."&lt;/label&gt;&lt;/td&gt;&lt;/tr&gt;"; echo "&lt;tr&gt;&lt;td colspan = '2'&gt;&lt;input type = 'checkbox' name='answer' onClick='javascript:checkone(1)' value = '100'&gt;&lt;label&gt;". $info['choice2_data'] ."&lt;/label&gt;&lt;/td&gt;&lt;/tr&gt;"; echo "&lt;tr&gt;&lt;td colspan = '2'&gt;&lt;input type = 'checkbox' name='answer' onClick='javascript:checkone(2)' value = '100'&gt;&lt;label&gt;". $info['choice3_data'] ."&lt;/label&gt;&lt;/td&gt;&lt;/tr&gt;"; echo "&lt;tr&gt;&lt;td colspan = '2'&gt;&lt;input type = 'checkbox' name='answer' onClick='javascript:checkone(3)' value = '100'&gt;&lt;label&gt;". $info['choice4_data'] ."&lt;/label&gt;&lt;/td&gt;&lt;/tr&gt;"; } mysql_close($con);?&gt; </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload