开发者

Session variables working when testing with Chrome and IE but not Firefox

I'm writing a quiz program using PHP and a bit of Javascript. The questions can be answered correctly when IE or Chrome is used but Firefox refreshes the page and increments the session variable.

Here's a code snippet:

 if(isset($_GET['answer1']))
{
    if($_GET['answer'] == $_GET['answer1'])
    {
        include 'config.php';
        if (!$con) {
        die('Could not connect: ' . mysql_error());
    }
    mysql_select_db($db, $con);
    $userId = $_SESSION['userId'];
    $wordNow = $_SESSION['word'];
    $sql3 = "SELECT * FROM userAccomplishments Where UserId = '$userId' AND 
    word = '$wordNow'";

    $result3 = mysql_query($sql3);
    if (mysql_num_rows($result3) == 0) {
    $sql4 = "SELECT wordId from allwords WHERE word = '$wordNow'";
    $result = mysql_query($sql4);
    if (!$result) {
        echo "Could not successfully run query ($sql) from DB: " . mysql_error();
        exit;
    }
    if (mysql_num_rows($result) == 0) {
        echo "No rows found, nothing to print so am exiting from random number";
        exit;
    }
    while ($row = mysql_fetch_assoc($result)) {
        $wordId = $row["wordId"];
        //       echo $row["word"] . " " ."<BR>" ;
    }
    list($usec, $sec) = explode(' ', microtime());
    $script_end = (float) $sec +开发者_运维知识库 (float) $usec;
    $elapsed_time = (float)($script_end - $script_start);
    $elapsed_time = $_GET['formvar'];
    $sql2 = "INSERT INTO userAccomplishments (UserId, word, TimeTaken, wordId)
        VALUES ('$userId',   '$wordNow', '$elapsed_time', '$wordId')";
    echo 'You got '. $wordNow . ' in  ' .$elapsed_time . ' seconds. <BR><BR>';
    $result = mysql_query($sql2);
    }         
     $_SESSION['views'] = $_SESSION['views'] + 1;
    }
    else
    {
         $_SESSION['views'] = $_SESSION['views'] + 1;
        echo 'Keep studying <BR>';
    }


}
else
{
    $_SESSION['views'] = 1;

}


Doesn't look like you're calling session_start(). Make sure you call it to get your session in gear! Woo! Yeah!

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜