Note that there are some explanatory texts on larger screens.

plurals
  1. POPhp sql session tally
    text
    copied!<p>Hey guys I am trying to make a online quiz consiting of 5 questions for uni, and am just trying to work out how i would make a tally using sql and php, currently I have an idea but it doesn't seem to work the way I was expecting. It was meant to request an answer and if it matched the sql column it would add a point to a $_SESSION['tally'] though currently no matter the answer it still adds 1 to tally... any help would be great guys</p> <pre><code> &lt;?php session_start(); if(!isset($_SESSION['idc'])) { $_SESSION['idc'] = 1; } $count = $_SESSION['idc']; $_SESSION['idc'] ++ ; if ($_SESSION['idc'] &gt;= 6) { session_destroy(); } $id = $_GET['id']; include('cdb.php'); echo "&lt;br&gt;&lt;br&gt;"; $sql = "SELECT * FROM tblas where id='$id';"; $results = mysql_query($sql, $db); $myrow = mysql_fetch_array($results); $id2 = "$id=1"; if ($_REQUEST['answer1'] === $myrow['correct']) { $_SESSION['tally'] ++ ; } ?&gt; &lt;br&gt;&lt;br&gt;&lt;br&gt; &lt;?php if ($count &gt;1 &amp;&amp; $count &lt;7) { echo 'Question: '.$myrow['question']; } echo $myrow['A']; ?&gt; &lt;form name="form2" method="post"&gt; &lt;select name="answer1"&gt; &lt;option value=$myrow['A']&gt;&lt;?php echo $myrow['A']?&gt;&lt;/option&gt; &lt;option value=$myrow['B']&gt;&lt;?php echo $myrow['B']?&gt;&lt;/option&gt; &lt;option value=$myrow['C']&gt;&lt;?php echo $myrow['C']?&gt;&lt;/option&gt; &lt;option value=$myrow['D']&gt;&lt;?php echo $myrow['D']?&gt;&lt;/option&gt; &lt;input type="submit" name="submit" value="Continue" onclick = "window.location.href = 'testttts.php?id=&lt;?php echo $count?&gt;'" &lt;/form&gt; &lt;br&gt;&lt;br&gt; &lt;br&gt;&lt;br&gt; &lt;br&gt;&lt;br&gt; &lt;?php $idc = $_SESSION['idc']; $tally = $_SESSION['tally']; echo "this is $ _ session tally: $tally"; Echo "&lt;br&gt; this is ID count: $idc"; ?&gt; </code></pre> <p>That should be all the relevant code, any questions or anything to help with this just ask and il do my best to help you help me! </p> <p>thank you for anyone who offers any help to this.</p> <p>sorry its messy normally its just me looking at it till its finished.</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