0

I have a list of 5 items and each has a corresponding button to it which changes its state. When these buttons are clicked for each of them, some database operations are performed and they change from 'Appear' to 'Request' and then last as 'Requested'. Now in the list whenever any item's button turns to 'Requested' state(after clicking from 'Appear' to 'Request'), the next item when clicked from 'Appear', stops at 'Request' and does not changes its state to 'Requested' on clicks. And again the third item's button in the list when clicked changes from 'Appear' to 'Request' and then 'Requested'. May I know what could be the possibility that is showing two different results for the same script. Any advice or help will be appreciated on this, stuck for a long time. Here is the complete code.

<?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
        }

        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
        }

        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
        }
    }

    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 );
    }

?>
Ansh
  • 269
  • 2
  • 15
  • Furthermore, you just assume that your sql queries execute without any errors, you do not confirm this by checking for errors. This way you cannot possibly have any clue as to what could have gone wrong. Also, using the mysql_*() api in 2017 is not such a great idea. Use pdo or mysqli instead. – Shadow Nov 28 '17 at 07:23
  • Thanks for the time but as I mentioned here in the question itself, my queries are definitely running fine for every alternate item in the list. – Ansh Nov 28 '17 at 07:45

0 Answers0