We’ve posted a new Expert Spotlight! Joe Anderson (DatabaseMX) has been on Experts Exchange since 2006. Learn more about this database architect, guitar aficionado, and Microsoft MVP.
// code for the place where user enter the code
<form action="Trivia.php?menu=set" method="post">
<span> Welcome, <br>
Enter Code To Play . »
<br />
<input type="text" name="name_full" style="width:150" />
<br />
<input type="hidden" name="email_id" style="width:0" />
<input type="hidden" name="total_question" value= "10" style="width:0" />
<input type="hidden" name="time" value= "1" style="width:0" />
<input type="image" src="images/start.jpg" />
<input type="hidden" name="next_step" value="true" />
</form>
//terms and condition page which i want to stop when user play for the 2nd time
<script language="javascript">
<!--
function Submit(frm)
{
if(!frm.accepted.checked){
alert('Please check the terms and conditions box.\n\nThank you.');
}
return frm.accepted.checked;
}
//-->
</script>
<form action="Trivia.php?menu=start" method="post" onsubmit="return Submit(this);">
<tr>
<td width="30%" style="text-align:right"> </td>
<td width="70%"><input type="hidden" name="total_question" value= "10" style="width:50" /></td>
</tr>
<tr>
<td width="30%" style="text-align:right"> </td>
<td width="70%"><input type="hidden" name="time" value= "1" style="width:50" />
</td>
</tr>
<tr>
<td width="30%" style="text-align:right"> </td>
<label>
I have read and accepts the terms & conditions: <input type="checkbox" name="accepted" value="1" />
</label>
</td>
</tr>
<input type="hidden" name="full_name" id="full_name" value="<?php echo $_SESSION['full_name']; ?>" /></td>
<tr><td></td><td><input type="image" src="images/start.jpg" />
<input type="hidden" name="next_step" value="true" />
</td></tr>
</table>
</form>
//
global $quiz_ready;
$quiz_ready = 'no';
if($_GET['menu']== 'set' && $quiz_ready=='no')
{
global $error,$total_question,$time_sec,$time_min,$cat1,$use_tedu,$total_rows,$correct,$wrong,$unanswered;
$query = "SELECT * FROM enter WHERE randomcode='{$_POST['name_full']}' ";
$res = mysql_query($query);
$query = "SELECT distinct quiz FROM enterused WHERE type = 0 and randomcode='{$_POST['name_full']}' ";
$ress = mysql_query($query);
$query = "SELECT distinct quiz FROM enterused WHERE type = 1 and randomcode='{$_POST['name_full']}' ";
$resp = mysql_query($query);
if (mysql_num_rows($res)){
$access_granted = true;
} else {
$access_granted = false;
$quiz_ready = 'no';
($_GET['menu']== 'setup');
}
if (mysql_num_rows($ress )>= 3){
$access_granted = false;
$quiz_ready = 'no';
($_GET['menu']== 'setup');
}
if (mysql_num_rows($resp )>= 5){
$access_granted = false;
$quiz_ready = 'no';
($_GET['menu']== 'setup');
}
if ($access_granted){
if(isset($_POST['next_step']) && isset($_POST['total_question']) && isset($_POST['time']) )
{
// Get random questions
$stamp = date('mdyHis');
$_SESSION['quiz_date'] = date('d-M-y ,D');
$_SESSION['quiz_time'] = date('H:i:s');
$_SESSION['quiz_id'] = $stamp;
$_SESSION['full_name'] = $_POST['name_full'];
$_SESSION['quiz_term'] = $_POST['accepted'];
$_SESSION['quiz_total_question'] = $_POST['total_question'];
$_SESSION['quiz_time_sec'] = $_POST['time'] * 60 ; // time in seconds
$_SESSION['quiz_time_msec'] = $_POST['time'] * 60 ;
$_SESSION['quiz_time_min'] = $_POST['time'];
$_SESSION['quiz_cat1'] = $_POST['cat1'];
$_SESSION['type'] = $_POST['type'];
$query = "SELECT * FROM pq_crtp_quiz";
$sql = mysql_query($query);
$total_rows = mysql_num_rows($sql);
$i=0;
array($rand_arr);
while($i < $_SESSION['quiz_total_question'])
{
$rand_num = rand(1,$total_rows - 1);
if(!@array_search($rand_num,$rand_arr))
{
$rand_arr[$i] = $rand_num;
$i++;
}
}
global $quiz_data;
for($i=0;$i < $_SESSION['quiz_total_question'];$i++)
{
$query = "SELECT distinct(id), question, option1, option2, option3, answer, category, counter FROM pq_crtp_quiz WHERE id = ".$rand_arr[$i];
$sql = mysql_query($query);
$quiz_data[$i] = mysql_fetch_array($sql);
}
$_SESSION['quiz_data']=$quiz_data;
//print_r($quiz_data);
}
elseif(isset($_POST['next_step']))
{
$error = "Some of the fields are left empty !";
header('Location: Trivia.php?menu=set');
}
} else {
header('Location: Trivia.php?menu=set');
$smarty->assign('errors', $errors);
$smarty->display('quiz.tpl');
exit();
}
}
//this is the code block which is inserting the T&C reference with user id when he plays for the first time and i think it needs to be used to create this new logic
$query = "insert into terms VALUES ('','". $_SESSION['quiz_term']."','".$userdata['username']. "','".$_SESSION['quiz_id']."')";
$sql = mysql_query($query);
Do more with
Premium Content
You need an Expert Office subscription to comment.Start Free Trial