Grow your CSS skills. Land your dream job.

php form is not submit after completion of time

  • # March 7, 2013 at 4:45 am

    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

    < ?php
    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 = “< ?php echo $_SESSION["start_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.”);
    }
    }
    }

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

    “;
    }

    ?>


    # March 7, 2013 at 6:32 am

    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();`)

    # March 7, 2013 at 6:46 am

    >Does this gives you an error? [script>

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

    # March 7, 2013 at 6:50 am

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

    # March 7, 2013 at 7:14 am

    Oh lol @Paulie_D :P

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

    # April 4, 2013 at 1:05 am

    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)

You must be logged in to reply to this topic.

*May or may not contain any actual "CSS" or "Tricks".