1

The following code will not submit the form to the page, even though it is supposed to. My form tags are declared in a page that is 2 layers up in the folder hierarchy and i made it so that it is able to communicate with the code that is 2 levels down in the hierarchy. My form method is post. This code won't run because the commands are out of sync and i cannot run the command.

public function getStudents()
    {
        $studentList = mysql_query("CALL GetLogin();")
        or die(mysql_error());
        $studentRows = mysql_num_rows($studentList);
        $counter = 1;

        while ($row = mysql_fetch_array($studentList))
        {
            echo '<tr>
            <td colspan="3"><center>
            <input type="checkbox" name="myselectedstudent' . $counter . '" value="' . $row["username"] . '">' . $row["username"] . '<br>
            </center></td>
            </tr>';
            $counter++;
        }
        echo '<tr>
        <td align="center" colspan="3"><br/><strong>
        <input type="submit" name="Submit" value="Confirm Student">
        </strong></td>
        </tr>';
        $counter = 0;

        while ( $counter <= $studentRows )
        {
            $counter++;
            if ( isset($_POST['myselectedstudent' . $counter . '']) )
            {
                $_SESSION["Student"] = $_POST['myselectedstudent' . $counter . ''];
                $this->getAllAssignedStudents( $_SESSION["Student"], $_SESSION["testName"], $_SESSION["user"] );

                if ( $counter == $studentRows )
                {
                    echo '<script language="javascript">
                    alert ( "Students Added!" );
                    </script>';
                    Header
                    ("Location: http://localhost/AndrewPHP/Greenboard/PresentationLayer/mainpageGUI.php?PageID=" . $_SESSION["accessLevel"] . "");
                }
            }
        }
    }
  • 1
    you canNOT output some html/JS, then expect a `header()` redirect to work. – Marc B Apr 02 '13 at 16:40
  • not originally. i just moved it to just under the submit button. i still got the 'commands out of sync' error. – user2236932 Apr 02 '13 at 16:43
  • 1
    commands out of sync sounds like a DB error. are you using pdo/mysqli in getAllAssignedStudents? the mysql_*() functions would NOT produce such an error. – Marc B Apr 02 '13 at 16:45
  • +1 @MarcB In my quick research I saw this happen a lot when simultaneous queries were ran. [Example 1](http://stackoverflow.com/a/614741/1134705) & [Example 2](http://stackoverflow.com/a/14561639/1134705) – jnthnjns Apr 02 '13 at 16:47
  • i just deleted the javascript alert boxes from above the header() function. The 'commands out of sync' error continues to prevent the header() function from executing. – user2236932 Apr 02 '13 at 16:48
  • @user2236932: this is NOT a js/html error. it is a php error, and you're doing something incorrect with database calls ON THE SERVER. – Marc B Apr 02 '13 at 16:49
  • i am using mysql_query in the getAllAssignedStudents() function – user2236932 Apr 02 '13 at 16:50
  • the function that connects to the database using variables like server, name, etc., is called by a class that is one layer up in the hierarchy. subsequently, that same class calls the getStudents() function – user2236932 Apr 02 '13 at 16:53

0 Answers0