0

I have checked online for at least three hours on a possible solution or workaround, but there doesn't seem to be anything working so far. I am quite new to all these platforms. I have two PHP files - the first is to log in and check the record from the database, and the second to display a set of query results based on the inputted info from the first page.

In the html section of my first php page, it goes like this:

                <form role="form" method="post" action="view_users.php">
                    <fieldset>
                        <div class="form-group">
                            <input class="form-control" placeholder="Course Number" name="courseNumber" type="text" autofocus>
                        </div>

                        <div class="form-group">
                            <input class="form-control" placeholder="Section" name="section" type="text" autofocus>
                        </div>
                        <div class="form-group">
                            <input class="form-control" placeholder="Student ID" name="studentId" type="text" id="studentId" autofocus>
                        </div>


                        <input class="btn btn-lg btn-success btn-block" type="submit" value="View Scores" name="register" >

                    </fieldset>
                </form>

And then in the lower part,

            <?php

            include("database/db_conection.php");
            $courseNumber=$studentId=$section="";  
            if(isset($_POST['register']))
            {
                if ($_SERVER["REQUEST_METHOD"] == "post")
                {
                    $courseNumber=$_POST['courseNumber'];
                $studentId=$_POST['studentId'];//same
                $section=$_POST['section'];//same

The second PHP file, view_users.php, is supposed to receive the three columns above from the first PHP file with below:

            <?php   

            include("database/db_conection.php");
            $view_users_query="select a.Q1, a.LAB1, a.LABEXER1, a.PE from ES201_M2_CS a inner join ES201 b on a.cid = b.cid where b.section = '$section' and b.sid = '$studentId';"; //line 41
            $run=mysqli_query($dbcon,$view_users_query);

I am encountering the error, however.

Notice: Undefined variable: section in /home/public_html/es201/view_users.php on line 41

Notice: Undefined variable: studentId in /home/public_html/es201/view_users.php on line 41

I have exhausted all the solutions that I found online, but to no avail. I tried printing the $POST value in the first PHP and all the inputted details were captured. However, in the second, all values would only display as NULL. I would appreciate any enlightenment on this. Thank you very much!

Lane
  • 366
  • 1
  • 2
  • 11
  • On view_users.pgp replace $studentId bu $POST['studentId']. Ont he second file you receive data from POST method setup on the html form. – MRodrigues Dec 07 '15 at 16:03
  • I'm getting the courseNumber, section and studentId fields inputted by the user from the first file and defines the method as POST. At the lower part, I created the $courseNumber, $section and $studentId from those fields and was able to display those correctly in the same form. In the second file, view_users.php, I tried to get those three values ($courseNumber) as part of an SQL query. – Lane Dec 07 '15 at 16:07
  • Cool! That works, although I still have to test further. I did somehow the same, but I replaced $studentId with $_GET[studentId]. Is it not supposed to get something from the first file? That was my understanding. Thank you. – Lane Dec 07 '15 at 16:11
  • When you press submit, all data is set to view_users,php . The bottom php part of the first file does nothing. In order to access your form inputs from view_users.php you must user the global $_POST array. Check this http://www.w3schools.com/php/php_forms.asp – MRodrigues Dec 07 '15 at 16:13

0 Answers0