-1

A timer java script is working fine on local server. But when i run it on hosting server it does not intiate the timer.

<script type="text/javascript" >
<?php
    $elapsed=time()-strtotime($_SESSION['starttime']);
    if(((int)$elapsed/60)<(int)$_SESSION['duration'])
    {
        $result=executeQuery("SELECT " .
        " TIME_FORMAT(TIMEDIFF(endtime,CURRENT_TIMESTAMP),'%H') as hour, ".
        " TIME_FORMAT(TIMEDIFF(endtime,CURRENT_TIMESTAMP),'%i') as  min, ".
        " TIME_FORMAT(TIMEDIFF(endtime,CURRENT_TIMESTAMP),'%s') as sec ".
        " FROM studenttest ".
        " WHERE stdid=".$_SESSION['stdid'].
        " AND testid=".$_SESSION['testid'].";");
        if($rslt=mysql_fetch_array($result))
        {
            echo "var hour=".$rslt['hour'].";";
            echo "var min=".$rslt['min'].";";
            echo "var sec=".$rslt['sec'].";";
        } else {
            $_GLOBALS['message']="Try Again";
        }
        closedb();
    } else {
        echo "var sec=01;var min=00;var hour=00;";
    }
?>
</script>
baljeet
  • 43
  • 6

2 Answers2

0

Replace

<?php

With

<?php
session_start();
Devator
  • 3,686
  • 4
  • 33
  • 52
0

After cleaning up your code more, stack overflow's code highlighting shows that your php output is surrounded in comment tags:

<!-- -->

so the javascript never see's the variables echo'd by PHP. Could this be your problem?

TerryProbert
  • 1,124
  • 2
  • 10
  • 28
  • 1
    The presence of the comment tags has no effect upon the execution of the Javascript code. This is done to support browsers that don't know what ` –  Apr 27 '12 at 19:50
  • Ahh, I never knew that! (+1) Thanks for the link @Phoenix – TerryProbert Apr 27 '12 at 20:20