check given answer answer if match random quest
<p>Hi I am using this code to generate random question:</p>

<pre><code>&lt;?php
session_start(); //this was missing from this file
//connect to db
require_once('db_conn.php');

$id=rand(0,13); //2nd number = highest ID

if ($res = $mysqli-&gt;query("SELECT quest FROM table WHERE ID='$id'")){

   $resQ = $res-&gt;fetch_assoc(); 
   echo "" . $resQ['quest'] . "";

   $_SESSION['chckanswer'] = $resQ['guest'];

   $res-&gt;close();
}
$mysqli-&gt;close();
?&gt;
</code></pre>

<p>and this one to try and check if answer given match the question:</p>

<pre><code>&lt;?php
session_start();

//more code

if($stmt = $mysqli-&gt;prepare('SELECT quest FROM table WHERE answer=?')){
    $stmt-&gt;bind_param("s", $_POST['given_answer']);
    $stmt-&gt;execute();
    $stmt-&gt;bind_result($quest);
    $stmt-&gt;fetch();

        if($_SESSION['chckanswer'] != $quest &amp;&amp; !empty($_SESSION['chckanswer'])){
        echo 'wrong';
        exit();
        }
        else{
        echo 'ok';
        }
    $stmt-&gt;close();    
}
//more code
</code></pre>

<p>But I get error <strong>undifined index chckanswer</strong></p>
