-2

I need some help with a PHP/MySQL multiple choice quiz that I'm making for a website.i am in new in php. I'm having trouble with the logic of browser back button.if user click on browser back button inbetween quiz.it goes on end of quiz and redirect result page.i am doing like this:-

<?php
include("connection.php");
$result = mysql_query("SELECT * FROM questions where id=1");
while($row = mysql_fetch_array($result)) 
{
echo $row['question_name'] ;
echo $row['answer1'] ;
echo $row['answer2'] ;
echo $row['answer3'] ;
echo $row['answer4'] ;
$_SESSION['exam']="true";
}
if($_SESSION['exam']=="false")
{
header('Location: expire.php');
}
?>
phpdev
  • 11
  • 3
  • 5
    Please add your code so we can help you! – KhorneHoly Jul 21 '14 at 07:40
  • [Please, stop using mysql_* functions](http://stackoverflow.com/q/12859942/1238019) in new code, they are [officially deprecated](https://wiki.php.net/rfc/mysql_deprecation). Instead of, have a look on [prepared statements](http://dev.mysql.com/doc/refman/5.0/en/sql-syntax-prepared-statements.html), and use [Mysqli](http://php.net/manual/en/book.mysqli.php) or [PDO](http://php.net/manual/en/book.pdo.php). – zessx Jul 21 '14 at 07:48

2 Answers2

1

To start a new session or resume an old one, add session_start() to the top of each PHP page that uses sessions:

http://php.net/manual/de/function.session-start.php

If you don't do that, your session won't work.

TimoStaudinger
  • 41,396
  • 16
  • 88
  • 94
0

Please use mysqli or PDO as mysql function already officially deprecated.

i'm not sure with the relation with your question and your code. Is it ok

$_SESSION['exam']="true";

Or it should be

$_SESSION['exam']=="true";

What do you mean by

if($_SESSION['exam']=="false")

do you mean if session['exam'] is not set? then it should

if(!isset($_SESSION['exam']))
Sharif Ahmed
  • 93
  • 1
  • 2
  • 10