0

我正在为一个项目开发 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 个撇号。

我只是删除了“不能”这个词,它已经开始工作了。

谢谢你们的帮助:)

4

3 回答 3

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 代码一个接一个地替换,然后您会发现代码失败的地方。

于 2013-03-18T04:19:46.273 回答
0

不要通过 javascript 来做,而是尝试在纯 PHP 中使用更好的方法。就像是:

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

如果你必须使用 JS,然后发出 AJAX 请求,那么你可以通过任何你喜欢的方式通过 JS 来操纵行为。

于 2013-03-18T04:17:36.717 回答
0

您将 HTML 表单放在哪里?是在同一个页面还是在不同的页面?从您的代码来看,似乎什么都没有做,所以我建议您检查您的提交按钮名称是否正确(提交)。HTML 应该是这样的:

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

    <input type="submit" name="submit" value="Submit"/>
</form>
于 2013-03-18T04:32:04.617 回答