Sign in
Log inSign up

isset condition behaves different on different clicks

anand shankar's photo
anand shankar
·Nov 29, 2017

I am working on a page in which there is a list of 5 chapters quiz and each chapter has 3 set of buttons (Appear, Request, Requested) which appear based on certain database conditions. When a user first time appears for the quiz for a particular chapter the button present there is 'Appear'. Now if he attempts and fails in the Quiz for that chapter, the button turns to 'Request'(as the user now needs permission to reappear for the quiz from the admin). Now when he clicks on the 'Request' button it does a set of database operations and the next button appears is 'Requested'. This is working fine for all the chapters but only in case if the user has 'Requested' for the previous chapter and goes to attempt and request the immediate next chapter, the state of button stays to 'Request' only rather than 'Requested'. I am having no clue on this about why is this not changing its state from 'Request' to 'Requested' on submit. Following is my code, Please a help would be life-saver for me and highly appreciated.

<?php include 'blocks/headerInc.php' ; ?>
<?php require_once "phpmailer/class.phpmailer.php";?>
<?php include 'blocks/leftnavInc.php' ; ?>
</div>
</div>
<div class="col-xs-12 col-sm-9 page-right">
<div class="panel panel-primary">
<div class="panel-heading">Quiz Module
<button type="reset" onClick="javascript:history.go(-1)" class="btn btn-danger" style="    margin-left: 86%;margin-top: -30px;"><i class="glyphicon glyphicon-ban-circle" ></i> Go Back</button> 
</div>
<div class="panel-body">
<table id="example" class="table table-striped table-hover table-bordered dataTable" cellspacing="0" width="100%">
     <thead>
       <tr>
        <th>S.No.</th>
        <th>Module Name</th>
        <th>Total Attempt</th>
        <th>Start Date</th>
        <th>Pass Date</th>
        <th style="display:none;">Due Date</th>
        <th style="text-align: center;">Action</th>
      </tr>
      </thead>
<tbody>
<?php
ob_start();
$created_on        =    $db->idToField("tbl_user", "created_on", $_SESSION['session_user_id']) ;
$sqlQuery        =    "SELECT * from tbl_question_module order by id ASC" ;
$sq             =     $db->query($sqlQuery);
if($db->affected_rows > 0)
{    
$i = 1;
$days_for_start    =    ''; 
$days_for_end     =     '';

while($row=mysql_fetch_array($sq))
    {
     extract($row);

$pass_fail_sql=mysql_query("select * from tbl_user_quiz_cleared where module_id='".$row['id']."' and chapter_id='0' and user_id='".$_SESSION['session_user_id']."'  order by id desc");
$pass_fail_data=mysql_fetch_array($pass_fail_sql);
$rows_count = mysql_num_rows($pass_fail_sql);
$clered=$pass_fail_data['cleared'];
if($clered=='1')
{
$date=$pass_fail_data['created'];
$dat=strtotime($date);              
$pass_date = date('d-m-Y', $dat);   
}
else
{
$pass_date='';
}
 if($fnc->getReattemptData($id,$_SESSION['session_user_id'], "days_for_start") !='')
 {
     $days_for_start    =    $fnc->getReattemptData($id, $_SESSION['session_user_id'], "days_for_start");
 }
 if($fnc->getReattemptData($id,$_SESSION['session_user_id'], "days_for_end") !='')
 {
     $days_for_end    =    $fnc->getReattemptData($id,$_SESSION['session_user_id'], "days_for_end"); 
 }
        $startDate = date("d-m-Y", strtotime($created_on. ' + '.$days_for_start.' days'));
     $end_date    =    date("d-m-Y", strtotime($created_on. ' + '.$days_for_end.' days'));     

?>                
<tr>

    <td align="center"><?php echo $i ; ?></td>
    <td><?php echo $title; ?></td>
    <td><?php echo $rows_count; ?></td>
    <td><?php echo $startDate; ?></td>
    <td><?php echo $pass_date; ?></td>

<td style="display:none;"><?php //echo $dueDate ; ?></td> 
   <?php 
     $pass_sql=mysql_fetch_array(mysql_query("select * from  tbl_user_quiz_cleared where user_id='".$_SESSION['session_user_id']."' and module_id='$id' and cleared='1' and chapter_id='0'"));
   ?>

 <td align="center">
     <?php
        $crtDate    =    date("Y-m-d h:i:s");
        $crtDate    =    strtotime($crtDate);
        $today_date=date('Y-m-d');
        $user_sql=mysql_fetch_array(mysql_query("select * from tbl_user where id='".$_SESSION['session_user_id']."'"));
        $glCorporateDay=$user_sql['request_updated_day'];
        $register_date=$user_sql['register_date'];
        $glDtRegister15=date('Y-m-d', strtotime('+ '.$glCorporateDay.' days', strtotime($register_date)) );
        $user_reattempt_sql=mysql_fetch_array(mysql_query("select * from tbl_user_reattempt where user_id='".$_SESSION['session_user_id']."'"));    // Added by Anand to obtain 15days grace.
        $grace = $user_reattempt_sql['days_for_end']; // Added by Anand to obtain 15days grace.
        $grace_date= date('Y-m-d', strtotime('+ '.$grace.' days', strtotime($startDate)) ); // Added by Anand to obtain 15days grace.

       if( ($rep->checkUserAttemptQuiz($_SESSION['session_user_id'], $id) <=2 ) && ($pass_sql==true))
          { 
         ?> 
         <input name="" type="button"  value="Cleared" class="btn btn-sm btn-default">
          <?php 
          }
      if(($glDtRegister15==$today_date || $grace_date==$today_date  ) && ($pass_sql==false) )   
          {
         echo '<input name="" type="button"  value="Disable" class="btn btn-sm btn-default">';
          }
      else
          {
      if($rep->checkUserAttemptQuiz($_SESSION['session_user_id'], $id) < 2  && (strtotime($end_date) >= $crtDate) && (strtotime($startDate) <= $crtDate) && ($pass_sql==false) ) 
          { 
       ?><input name="" type="button" onClick="javascript:window.location.href='instructions.php?moduleId=<?php echo $fnc->encode($id) ; ?>';" value="Appear" class="btn btn-sm btn-info">
                              <?php }else{
                            //

                                } ?>
                             <!--  <?php

                               ?> 
                            <input name="" type="button"  value="Overdue"  onClick="javascript:window.location.href='instructions.php?moduleId=<?php// echo $fnc->encode($id) ; ?>';" class="btn btn-sm btn-success">
                                 <?php 
                               //  }
                                 ?> -->

     <!---3rd time  -->                           

                    <?php 

                     if(($rep->checkUserAttemptQuiz($_SESSION['session_user_id'], $id) == 2) && ($pass_sql==false ) )
                          { 

                          $module_get=mysql_fetch_array(mysql_query("select * from module_quiz_request_user where request_attempt='3' and user_id='".$_SESSION['session_user_id']."' and module_id='$id'"));

                         ?> 

                      <form action= "moduleList.php" method="POST">
                        <?php  
                          if(($module_get['request_status']=='1')&&($module_get['quiz_status']=='1'))
                            {
                          ?>
                           <input name="" type="button"  value="Requested" class="btn btn-sm btn-success">
                          <?php }
                          ?>
                          <?php  
                           if($module_get['request_status']=='2')
                           {
                           ?>
                          <input name="" type="button" onClick="javascript:window.location.href='instructions.php?moduleId=<?php echo $fnc->encode($id) ; ?>';" value="Appear" class="btn btn-sm btn-success">
                          <?php }
                           ?>
                          <?php  
                              if(($module_get==false)) 
                                {
                           ?> 
                           <input name="request_3" type="submit"  value="Request" class="btn btn-sm btn-info">
                           <input name="module_id" type="hidden"  value="<?php echo $id;?>" class="btn btn-sm btn-success"> 

                            </form>
                                               <?php }  ?>
                                               <?php } 
                                               ?>

    <?php 
}                      
    ?>

                </td>

                </tr>
<?php $i++; } } ?>               
              </tbody>
            </table>
        </div>
      </div>
    </div>
    <!--/.sidebar-offcanvas-->
  </div>
</div>
<?php include 'blocks/footerInc.php' ; ?>   

 <?php 
if(isset($_POST['request_3']))
 {
   $user_id=$_SESSION['session_user_id'];
   $module_id=$_POST['module_id'];
   $request_status='1';  
   $designation_get=mysql_fetch_array(mysql_query("select * from tbl_user where id='$user_id'"));
   $designation=$designation_get['designation'];
   $salutation=$designation_get['salutation'];
   $user_register_date=$designation_get['register_date'];
   $corporate_id=$designation_get['created_by'];
   $request_updated_day=$designation_get['request_updated_day'];
   $level_designation=mysql_fetch_array(mysql_query("select * from  tbl_level_email where attemp='3' and designation_id='$designation'"));
   $designation_email=$level_designation['designation_email'];
   $data = array("module_id"=>$module_id,"user_id"=>$user_id, "request_status"=>$request_status,"created_date"=>date('Y-m-d'),"request_attempt"=>"3","user_permission"=>$designation_email,"quiz_status"=>"1");
   $db->query_insert("module_quiz_request_user", $data);
}

?>