2013-03-18 214 views
0

我正在处理一个项目的PHP和MYSQL,我在这里遇到了一个奇怪的问题,我点击表单上的提交按钮,它会运行这些代码。然而奇怪的问题是页面返回空白,而不是返回到带有表单的页面。我搜索了几个小时的错误,但找不到它。PHP&MYSQL返回空白页

请指出我的错误。感谢您的帮助。

<?php 
include '../database.php'; 

if(isset($_POST['submit'])) { 

    if (isset($_POST['stuid_0'])){ 

     $student = $_POST['stuid_0']; 


     //query moderator details 
     $query = mysql_query(" SELECT ModeratorID FROM Student WHERE StuID ='$student' ") or die(mysql_error()); 
     $info = mysql_fetch_assoc ($query); 
     $dbmoderator = $info['ModeratorID']; 

      //check for changes of status in supervisor 
      $query2 = mysql_query(" SELECT SupervisorID FROM Student WHERE StuID ='$student' ") or die(mysql_error()); 
      $value = mysql_fetch_assoc ($query2); 
      $dbsupervisor = $value['SupervisorID']; 
      $query3 = mysql_query(" SELECT LectStatus FROM Lecturer WHERE LectID ='$dbsupervisor' ") or die(mysql_error()); 
      $value2 = mysql_fetch_assoc ($query3); 
      $dbsupervisorstatus = $value2['LectStatus']; 

      //if no changes in supervisor 
      if ($dbsupervisorstatus=='2'){ 
       echo ("<SCRIPT LANGUAGE='JavaScript'> 
       window.alert('Moderator can't be promoted') 
       window.location.href='../committee/committee_supervisor2.php' 
       </SCRIPT>"); 

      } 
      else{ 
      //newly assigned a supervisor if previous supervisor status is not active 
      $query4 = "UPDATE Student SET SupervisorID='$dbmoderator', SupervisorStatus='1', ModeratorID=NULL WHERE StuID='$student'"; 
      mysql_query($query4); 

      echo ("<SCRIPT LANGUAGE='JavaScript'> 
       window.alert('Successfully updated') 
       window.location.href='../committee/committee_supervisor2.php' 
       </SCRIPT>"); 
      } 
    } 
    else 
     echo ("<SCRIPT LANGUAGE='JavaScript'> 
     window.alert('You must choose a moderator to be promoted') 
     window.location.href='../committee/committee_supervisor2.php' 
     </SCRIPT>"); 
} 
?> 

更新: 我认为,当系统运行在这一点上

if ($dbsupervisorstatus=='2'){ 

当我放回声“测试”的问题发生;在这条线之前,它仍然有效。

更新2:

我发现该代码可以运行,当我把

if ($dbsupervisorstatus=='2'){ 
       echo "Moderator can't be promoted"; 

      } 

以及

if($dbsupervisorstatus == 2){ 
    header("location:commitee_supervisor2.php"); 
    } 

但是我不明白为什么我的原代码

if ($dbsupervisorstatus=='2'){ 
       echo ("<SCRIPT LANGUAGE='JavaScript'> 
       window.alert('Moderator can't be promoted') 
       window.location.href='../committee/committee_supervisor2.php' 
       </SCRIPT>"); 

      } 

不工作..有一点帮助请.. :)

最后更新

伙计们,我知道这是为什么。

这是因为

window.alert('Moderator can't be promoted') 

在这3撇号。

我只是删除了“can not”一词,而且它的工作已经完成。

谢谢你们的帮助:)

+0

您是否打开了错误报告? ('error_reporting(E_ALL)') – castis 2013-03-18 04:09:26

+1

你为什么不直接做一个重定向到你的commitee_supervisor2页面而不是通过javascript来做呢? – coder101 2013-03-18 04:12:44

+0

castis,你能教我如何打开错误报告吗?我应该在哪里放? PS。即时通讯新手在PHP .. TQ的响应。 – user2126678 2013-03-18 04:14:02

回答

0

而是通过JavaScript这样做的,尽量使用纯PHP一个更好的方法。喜欢的东西:

if($dbsupervisorstatus == 2){ 
    header("location:commitee_supervisor2.php"); 
    } 

如果你必须使用JS,然后作出一个AJAX请求,那么你就可以通过操纵JS反正你喜欢的行为。

1

使用JavaScript代码仍然有效,但调试的起点是在所有回声JavaScript的地方回显普通文本。这将帮助你知道你的代码在什么时候开始失败。例如

//if no changes in supervisor 
      if ($dbsupervisorstatus=='2'){ 
       echo ("<SCRIPT LANGUAGE='JavaScript'> 
       window.alert('Moderator can't be promoted') 
       window.location.href='../committee/committee_supervisor2.php' 
       </SCRIPT>"); 

      } 

//if no changes in supervisor 
      if ($dbsupervisorstatus=='2'){ 
       echo "Moderator can't be promoted"; 

      } 

更换做到这一点在所有回声点然后开始更换一个其他的与你的JavaScript代码后再次,那么你就在那里你的代码没有察觉出来。

0

你把你的HTML表单放在哪里?它是在同一页面还是在不同的页面中?从你的代码看起来好像没有任何事情可做,所以我建议你检查你的提交按钮名是否正确(提交)。 HTML应该是这样的:

<form name="your_form"> 
    <!-- Your form here --> 

    <input type="submit" name="submit" value="Submit"/> 
</form> 
+0

您好,我确认它正在工作,因为可以显示回显,但是如果我使用了原始代码,它不再工作了。我在其他模块中使用了它,它的工作正常。您认为什么?感谢您的答复 :) – user2126678 2013-03-18 08:15:58