Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>The question wording is very confusing, but the first sentence says "I made a random question, my problem is how to save it and identify if it is already saved in the database."</p> <p>To take a stab at that, perhaps this is what you're looking for:</p> <pre><code>&lt;?php $con = mysql_connect("localhost","root","") or die('Could not connect:'. mysql_error()); mysql_select_db("db_compre", $con); $result = mysql_query("SELECT 1 FROM examquestion_table WHERE examreference_id = '{$exam_id}' AND subjectreference_id = '{$sub_id}'"); list($exists) = mysql_fetch_row($result2); if (!$exists) mysql_query("INSERT INTO examquestion_table (examreference_id, subjectreference_id) VALUES ('{$exam_id}', '{$sub_id}')"); mysql_close($con); ?&gt; </code></pre> <p>I don't see any form or reference to 'sub' in the code you posted, so I'm not sure what you mean by that.</p> <p><hr /> <strong>EDIT</strong> - OP edited code in question</p> <p>With your code, you could potentially get a PHP Notice saying that 'sub' is an undefined index in $_GET, which is the case if <code>$_GET['sub']</code> is not set.</p> <p>Check the form that this page is called from. If the <code>method</code> property is set to 'POST', then you need to use <code>$_POST['sub']</code>.</p> <p>You could also use <code>$_REQUEST['sub']</code> to get it from either, but keep in mind that this checks GET, POST, and COOKIES, so make sure you won't have any conficts before using this method.</p> <p>I would start with doing this:</p> <pre><code>&lt;?php echo "GET:"; var_dump($_GET); echo "&lt;br /&gt;&lt;br /&gt;POST:"; var_dump($_POST); ?&gt; </code></pre> <p>That will show you what data is in each.</p>
 

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