在a.php页面中,有一个Grade()用于计算分数的函数,是用JS写的。
Grade()函数部分代码如下:
function Grade()
{
   lastscore=Math.round(correct/Total_Question*100);   window.location.href="score.php?score="+lastscore;
    ReportScore(correct);
}我用window.location.href="score.php?score="+lastscore;将lastscore传到score.php页面,但是有时在score.php页面竟然收不到score值。有什么办法可以解决这个问题???

解决方案 »

  1.   

    Grade()代码如下:
    function Grade()
    {
      var correct = 0
      var wrong = 0
      for (number=0; number < Total_Question; number++)
        {
          var form = document.forms[number]      // Question #
          var i = GetSelectedButton(form.q1)
          if (form.q1[i].value == "1")
     { correct++ } 
    else 
     { wrong++
       msg += "Question "+(number+1)+"."
      +Solution[number]+"<BR>"
     }
        }
        lastscore=Math.round(correct/Total_Question*100); window.location.href="score.php?score="+lastscore;
        ReportScore(correct);
    }
    Grade()所在的页面即是test.php。score.php的代码如下:
    <?
      include("db_conn.php");
      include("session.php");  $Name=$_SESSION['userID'];
      $SQLstr="select * from stepcontrol where UserId='$Name'";
      $res=mysql_query($SQLstr);
      if(mysql_num_rows($res)>0)
      {
      $Sql="update stepcontrol set score='$score' where UserId='$Name'";
      mysql_query($Sql);   echo "<script>";
      echo "location.href=\"test.php\";";
      echo "</script>";
      }
      else
      {
      echo "<script>";
      echo "alert(\"Please Sign in before\");";
      echo "location.href=\"index.php\";";
      echo "</script>";
      }
    ?>它并不是收不到值,而是偶尔收不到值。
      

  2.   

    在$Name=$_SESSION['userID']; 
    前面加上
    $score = $_GET["score"];
      

  3.   

    怎么得不到呢?你把lastscore打印出来看看有值没
      

  4.   

    你试试这个
    window.location.href="score.php?score="+lastscore.toString(); 
      

  5.   

    我想问一下是不是PHP的值一传过去那个score.php就自动执行的?我并没有显示调用score.php页面
      

  6.   

    window.location.href就表示你要刷新当前窗口为score.php了
      

  7.   

    页面跳转了没,怀疑window.location.href="score.php?score="+lastscore;没执行。
      

  8.   

    请问一下,浏览器对PHP代码的执行结果有影响的么?
    在我的机上能接收到$score的值,但是在我同事机上却接收不要,即使接受到了但那个$score值为0.
      

  9.   

    score.php的代码 
    <? 
      include("db_conn.php"); 
      include("session.php");   $score=$_GET['score'];
      echo $score;
      exit;
      //看看有值不
      $Name=$_SESSION['userID']; 
      

  10.   

    只要你的浏览器地址栏里能看到...score.php?score=1234,用$_GET['score']就应该能取到值!
      

  11.   

    window.location.href="score.php?score="+lastscore + "&t=" + (new Date().getTime());