Forums

The forums ran from 2008-2020 and are now closed and viewable here as an archive.

Home Forums Back End php form is not submit after completion of time

  • This topic is empty.
Viewing 6 posts - 1 through 6 (of 6 total)
  • Author
    Posts
  • #43212
    narasimharao
    Member

    i am writing php quiz application with timer and score will generated after submition of form.but my problem is form is not submited after complection of time

    session_start();
    $minutes = 1; // Enter minutes
    $seconds = 0; // Enter seconds
    $time_limit = ($minutes * 60) + $seconds + 1; // Convert total time into seconds
    if(!isset($_SESSION[“start_time”])){$_SESSION[“start_time”] = mktime(date(G),date(i),date(s),date(m),date(d),date(Y)) + $time_limit;} // Add $time_limit (total time) to start time. And store into session variable.
    ?>




    [script>
    var ct = setInterval(“calculate_time()”,100); // Start clock.
    function calculate_time()
    {
    var end_time = ““; // Get end time from session variable (total time in seconds).
    var dt = new Date(); // Create date object.
    var time_stamp = dt.getTime()/1000; // Get current minutes (converted to seconds).
    var total_time = end_time – Math.round(time_stamp); // Subtract current seconds from total seconds to get seconds remaining.
    var mins = Math.floor(total_time / 60); // Extract minutes from seconds remaining.
    var secs = total_time – (mins * 60); // Extract remainder seconds if any.
    if(secs < 10){secs = "0" + secs;} // Check if seconds are less than 10 and add a 0 in front.
    document.getElementById(“txt”).value = mins + “:” + secs; // Display remaining minutes and seconds.
    // Check for end of time, stop clock and display message.
    if(mins <= 0)
    {
    if(secs <= 0 || mins < 0)
    {
    clearInterval(ct);
    document.getElementById(“txt”).value = “0:00”;
    document.f1.submit();
    alert(“The time is up.”);
    }
    }
    }

    include(“connection.php”);

    $display = mysql_query(“SELECT * FROM tbl_questions ORDER BY Qno “);

    if (!@$_POST) {

    echo “

    “;
    echo “

    “;

    while ($row = mysql_fetch_array($display))
    {

    $id = $row[“Qno”];
    $question = $row[“question”];
    $opt1 = $row[“option1”];
    $opt2 = $row[“option2”];
    $opt3 = $row[“option3”];
    $opt4 = $row[“option4”];
    $answer = $row[“answer”];

    echo “

    “;
    echo “

    “;

    }

    echo “

    $id&nbsp&nbsp$question
    $opt1 $opt2 $opt3 $opt4

    “;
    echo ““;
    echo “

    “;
    }

    else if($_POST)
    {

    //echo”executed”;
    $score = 0;
    $total = mysql_num_rows($display);

    while ($result = mysql_fetch_array($display)) {

    $answer = $result[“answer”];
    $id = $result[“Qno”];
    $or=q.$id;
    //echo”$or”;

    if ($_POST[$or] == $answer) {
    $score++;
    }

    }

    echo “

    You scored $score out of $total

    “;
    }

    ?>


    #127298
    CrocoDillon
    Participant

    Do you have a live demo? Codepen?

    Does this gives you an error? `[script>`

    And this? `document.f1.submit();` (I think it should be `document.forms.f1.submit();`)

    #127302
    Paulie_D
    Member

    >Does this gives you an error? [script>

    That was me…I had to change < to [ so it would render correctly on the forum.

    #127306
    narasimharao
    Member

    thank you,actually in my code have some html tags in the above code don’t have any html code it is not working…

    #127308
    CrocoDillon
    Participant

    Oh lol @Paulie_D :P

    `document.forms.f1.submit();` or live demo / codepen.

    #130597
    ankit88
    Participant

    i am using the same code in my online quiz…but the problem is that i want take time difference in minute and second format…and that difference i want to store in database(i.e. it user starts at 15.00 min and ends at 13.00 min the the difference will be 2 min, this value i want to store in database )……….how can i do that please provide me some code for solving this problem…..?????????

Viewing 6 posts - 1 through 6 (of 6 total)
  • The forum ‘Back End’ is closed to new topics and replies.