undefined index id

i having a problem with the undefined index id with my class_student.php on line 3… i got two page here linked to class student page where the error occur…

here my student_class.php

[php]<?php include ('session.php'); ?>

<?php include('header.php'); $user_query = mysql_query("select * from student where student_id='$session_id'") or die(mysql_error()); $user_row = mysql_fetch_array($user_query); ?>
<?php include('navhead_student.php'); ?>

<div class="container">
    <div class="row-fluid">
        <div class="span3">
            <div class="hero-unit-3">
                <div class="alert-index alert-success">
                    <i class="icon-calendar icon-large"></i>
                    <?php
                    $Today = date('y:m:d');
                    $new = date('l, F d, Y', strtotime($Today));
                    echo $new;
                    ?>
                </div>
            </div>
            <div class="hero-unit-1">
                <ul class="nav  nav-pills nav-stacked">
                    <li class="nav-header">Links</li>
                    <li>
                        <a href="student_home.php"><i class="icon-home icon-large"></i>&nbsp;Home
                            <div class="pull-right">
                                <i class="icon-double-angle-right icon-large"></i>
                            </div>  
                        </a>

                    </li>
                    <li class="active">
                        <a href="student_class.php"><i class="icon-group icon-large"></i>&nbsp;Class
                            <div class="pull-right">
                                <i class="icon-double-angle-right icon-large"></i>
                            </div>  
                        </a></li>

                </ul>
            </div>

        </div>
        <div class="span9">

            <div class="hero-unit-3">
                <table cellpadding="0" cellspacing="0" border="0" class="table table-striped table-bordered" id="example">
                    <div class="alert alert-info">
                        <button type="button" class="close" data-dismiss="alert">&times;</button>
                        <strong><i class="icon-user icon-large"></i>&nbsp;My Classes</strong>
                    </div>
                    <thead>
                        <tr>

                            <th>Class</th>
                            <th>Subject</th>
                            <th>Teacher</th>
                        </tr>
                    </thead>
                    <tbody>

                        <?php
                        $query = mysql_query("select * from sws where  student_id='$session_id'") or die(mysql_error());
                        while ($row = mysql_fetch_array($query)) {
                            $class_id = $row['class_id'];
                            $teacher_id = $row['teacher_id'];

                            $teacher_query = mysql_query("select * from teacher where teacher_id='$teacher_id'") or die(mysql_error());
                            $teacher_row = mysql_fetch_array($teacher_query);
                            ?>
                            <tr class="odd gradeX">


                                <td><?php echo $row['cys']; ?></td>
                                <td><a rel="tooltip"  title="View Class" id="v<?php echo $class_id; ?>"  href="class_student.php<?php echo '?id=' . $class_id; ?>" class="btn btn-info">&nbsp;<i class="icon-file-alt icon-large"></i>&nbsp;<?php echo $row['subject_id']; ?></a></td> 
                                <td><?php echo $teacher_row['firstname'] . " " . $teacher_row['lastname']; ?></td>   

                            </tr>
<?php } ?>
                    </tbody>
                </table>
                <!-- end slider -->
            </div>
        </div>

    </div>
<?php include('footer.php'); ?>
</div>
[/php]

And here is my class_student.php where the undefined id error occur at line 3

[php]<?php include('session.php'); ?>

<?php $get_id = $_GET['student_id']; include('header.php'); $user_query = mysql_query("select * from student where student_id='$session_id'") or die(mysql_error()); $user_row = mysql_fetch_array($user_query); ?> <?php $query_class = mysql_query("select * from class where class_id='$get_id'") or die(mysql_error()); $row_class = mysql_fetch_array($query_class); $teacher_id = $row_class['teacher_id']; $teacher_query=mysql_query("select *from teacher where teacher_id='$teacher_id'")or die(mysql_error()); $teacher_row= mysql_fetch_array($teacher_query); ?>
<?php include('navhead_student.php'); ?>

<div class="container">
    <div class="row-fluid">
        <div class="span3">
            <div class="hero-unit-3">
                <div class="alert-index alert-success">
                    <i class="icon-calendar icon-large"></i>
                    <?php
                    $Today = date('y:m:d');
                    $new = date('l, F d, Y', strtotime($Today));
                    echo $new;
                    ?>
                </div>
            </div>
            <div class="hero-unit-1">
                <ul class="nav  nav-pills nav-stacked">
                    <li class="nav-header">Links</li>
                    <li>
                        <a href="student_home.php"><i class="icon-home icon-large"></i>&nbsp;Home
                            <div class="pull-right">
                                <i class="icon-double-angle-right icon-large"></i>
                            </div>  
                        </a>

                    </li>
                    <li class="active">
                        <a href="student_class.php"><i class="icon-group icon-large"></i>&nbsp;Class
                            <div class="pull-right">
                                <i class="icon-double-angle-right icon-large"></i>
                            </div>  
                        </a></li>

                </ul>
            </div>

        </div>
        <div class="span9">

            <a href="student_class.php" class="btn btn-success"><i class="icon-arrow-left"></i>&nbsp;Back</a>
            <br><br>
            <div class="alert">Class:<a href="" >&nbsp;<strong><?php echo $row_class['course_id']; ?></strong></a>
                &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;
                Subject:<a href="">&nbsp;<strong><?php echo $row_class['subject_id']; ?></strong></a>
                &nbsp;
                Teacher::<a href="">&nbsp;<strong><?php echo $teacher_row['firstname']." ".$teacher_row['lastname']; ?></strong></a>
            </div>

            <div class="hero-unit-3">
                <table cellpadding="0" cellspacing="0" border="0" class="table table-striped table-bordered" id="example">
                    <div class="alert alert-info">
                        <button type="button" class="close" data-dismiss="alert">&times;</button>
                        <strong><i class="icon-user icon-large"></i>&nbsp;Files</strong>
                    </div>
                    <thead>
                        <tr>

                            <th>File Name</th>
                            <th>Description</th>
                            <th>Date Uploaded</th>
                            <th>Action</th>
                        </tr>
                    </thead>
                    <tbody>
                        <?php
                        $query = mysql_query("select * from files where class_id = '$get_id'") or die(mysql_error());
                        while ($row = mysql_fetch_array($query)) {
                            $file_id = $row['file_id'];
                            ?>
                            <tr class="odd gradeX">

                                <!-- script -->
                        <script type="text/javascript">
                            $(document).ready(function(){
                                                                
                                $('#d<?php echo $file_id; ?>').tooltip('show')
                                $('#d<?php echo $file_id; ?>').tooltip('hide')
                            });
                        </script>
                        <!-- end script -->

                        <td><?php echo $row['fname'] ?></td>
                        <td><?php echo $row['fdesc']; ?></td> 
                        <td><?php echo $row['fdatein']; ?></td>
                        <td width="50">
                            <a href="<?php echo $row['floc']; ?>" rel="tooltip"  title="Download File" id="d<?php echo $file_id; ?>"  role="button"  data-toggle="modal" class="btn btn-info"><i class="icon-download-alt icon-large"></i></a>

                        </td>

                        </tr>
                    <?php } ?>
                    </tbody>
                </table>
                <!-- end slider -->
            </div>
        </div>

    </div>
    <?php include('footer.php'); ?>
</div>
[/php]

Your code is obsolete and highly insecure.

Well, your code is no obsolete, just not secure. But, that is no answer or help, Kevin !

Aquilina, there are lots of problems in the code. First, the $_GET that you use to capture the
id get’s it from the passed on variable named “$student_id”. But, in your code for the first part,
you set it up this way:
href=“class_student.php<?php echo '?id=' . $class_id; ?>”

First, there is no ?id in the correct place and it is not $student_id…
Perhaps something like:
href=“class_student.php?student_id=<?php echo $class_id; ?>”
might work for you.

Not sure if this helps or not. The page is quite messy and I am guessing that is what Kevin was
talking about. Most good programmers do not use passed HREF’s anymore as they can be hacked
with ease. If you just peek at someone’s code on a page with them, you can see how they are
passing values and hack in your own PHP code to fake these and steal all your info…

Anyways, hope that helps a bit…

Ernie,
The Mysql code IS obsolete. Perhaps you prefer the word deprecated instead…

Helping people get or keep “Deprecated” code alive is not helping anyone. My help is in my signature where I have provided a link to a working PDO bumpstart database to get people off the deprecated code.

The page is quite messy and I am guessing that is what Kevin was talking about.
Not at all. I was specifically referencing the deprecated Mysql calls only. You made no reference to the poster that the code is deprecated. As an "Expert Helper", don't you think that is rather important to mention?

PS: Good job on Keeping the help flowing. JimL and I have not been active here lately. You came back at a good time to fill the slack.

Well, Kevin, yes, I do agree “Deprecated” code should be updated at some point.
But, mentioning that after you help solve someone’s problem is a great thing and helpful.
Just leaving it at that does not help them learn what they did wrong. Yes, MySQL is outdated,
but, moving to MySQLi or PDO is a big job and most newbies or beginner’s can not take that on
all at once. Much better to assist them fixing their current errors and THEN help them update to
the newer “standard”. Also, since PHP will have to be “backwards-compatible” for 10 years or more,
it is most likely that the new “standard” will not be a problem in many years. So, that is my viewpoint!

Now, Aquilina’s problem was due to them not placing the correct “GET” option when they call their
routine and therefore, no data sent to it.

Mysqli was available TEN years ago :o starting with PHP version 4.1. Dont you think it is well time for code to be updated?

When your building a house, the first thing you do is start with a solid foundation. All I am saying is it it should at least be mentioned in the responses to the problem.

Sponsor our Newsletter | Privacy Policy | Terms of Service