i have problem when adding a subject it got two subject that need to be selected by teacher , management sub and DBMS sub.. said Cannot modify header information - headers already sent by (output started at C:\xampp\htdocs\PhpProject3\navhead_user.php:57) in C:\xampp\htdocs\PhpProject3\teacher_add_subject.php on line 104.. when i select one of them it appear that error.. but when i select DBMS it inserted the subject but with error.. let say 1st i selecting management as the subject, it occur error but after refresh the page it appear in the list of the teacher subject then i add another subject DBMS subject and it occur error but the management subject is dissappear from the teach subject list.. but i try to add the management subject again it said it existed but not listed.. but in my database it inside there already only the data not appear..

teacher_add_subject.php

<?php include ('session.php'); ?>
<?php
include('header.php');
$user_query = mysql_query("select * from teacher where teacher_id='$session_id'") or die(mysql_error());
$user_row = mysql_fetch_array($user_query);
?>
<body>

    <?php include('navhead_user.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="teacher_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>
                            <a href="teacher_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>
                        <li  class="active"><a href="teacher_subject.php"><i class="icon-file-alt icon-large"></i>&nbsp;Subjects
                                <div class="pull-right">
                                    <i class="icon-double-angle-right icon-large"></i>
                                </div>  
                            </a></li>
                        <li><a href="students.php"><i class="icon-group icon-large"></i>&nbsp;Students
                                <div class="pull-right">
                                    <i class="icon-double-angle-right icon-large"></i>
                                </div>  
                            </a></li>


                    </ul>
                </div>

            </div>
            <div class="span9">
                <a href="teacher_subject.php" class="btn btn-success"><i class="icon-arrow-left icon-large"></i>&nbsp;Back</a>
                <br>
                <br>

                <div class="alert alert-info">
                    <button type="button" class="close" data-dismiss="alert">&times;</button>
                    <strong><i class="icon-user icon-large"></i>&nbsp;Add Subject</strong>
                </div>
                <div class="hero-unit-2">
                    <form class="form-horizontal" method="POST">
                        <div class="control-group">
                            <label class="control-label" for="inputEmail">Subject</label>
                            <div class="controls">

                                <select name="subject" class="span6">
                                    <option></option>
                                    <?php
                                    $query = mysql_query("select * from subject") or die(mysql_error());
                                    while ($row = mysql_fetch_array($query)) {
                                        ?>
                                        <option value="<?php echo $row['subject_id']; ?>"><?php echo $row['subject_title']; ?></option>
                                    <?php } ?>
                                </select>
                            </div>
                        </div>

                        <div class="control-group">
                            <div class="controls">
                                <button type="submit" name="save_subject" class="btn btn-success"><i class="icon-plus-sign icon-large"></i>&nbsp;Add Subject</button>
                            </div>
                            <br>
                            <?php
                            if (isset($_POST['save_subject'])) {
                                $subject = $_POST['subject'];

                                $result = mysql_query("select * from teacher_suject where teacher_id='$session_id' and subject_id='$subject'") or die(mysql_error());
                                $count = mysql_num_rows($result);

                                if ($count > 0) {
                                    ?>
                                    <div class="alert alert-danger">Subject <strong>Already Exist</strong></div>
                                    <?php
                                } else {


                                    mysql_query("insert into teacher_suject (subject_id,teacher_id) values('$subject','$session_id')") or die(mysql_error());
                                    header('location:teacher_subject.php');
                                }
                            }
                            ?>

                        </div>
                    </form>



                    <!-- end slider -->
                </div>
            </div>

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


</body>
</html>

teacher_subject.php

<?php include ('session.php'); ?>
<?php
include('header.php');
$user_query = mysql_query("select * from teacher where teacher_id='$session_id'") or die(mysql_error());
$user_row = mysql_fetch_array($user_query);
?>
<body>

    <?php include('navhead_user.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="teacher_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>
                            <a href="teacher_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>
                        <li   class="active"><a href="teacher_subject.php"><i class="icon-file-alt icon-large"></i>&nbsp;Subjects
                                <div class="pull-right">
                                    <i class="icon-double-angle-right icon-large"></i>
                                </div>  
                            </a></li>
                        <li><a href="students.php"><i class="icon-group icon-large"></i>&nbsp;Students
                                <div class="pull-right">
                                    <i class="icon-double-angle-right icon-large"></i>
                                </div>  
                            </a></li>


                    </ul>
                </div>

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



                <a href="teacher_add_subject.php" class="btn btn-success"><i class="icon-plus-sign icon-large"></i>&nbsp;Add Subject</a>
                <br>
                <br>
                <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;Subject Table</strong>
                        </div>
                        <thead>
                            <tr>

                                <th>Course Code</th>
                                <th>Course Description</th>
                                <th>Action</th>
                            </tr>
                        </thead>
                        <tbody>
                            <?php
                            $teacher_subject_query = mysql_query("select * from teacher_suject where teacher_id='$session_id'") or die(mysql_error());
                            $teacher_row = mysql_fetch_array($teacher_subject_query);
                            $subject_id = $teacher_row['subject_id'];

                            $query = mysql_query("select * from subject where subject_id = '$subject_id'") or die(mysql_error());
                            while ($row = mysql_fetch_array($query)) {
                                $id = $row['subject_id'];
                                ?>
                                   <!-- script -->
                            <script type="text/javascript">
                                $(document).ready(function(){

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

                                    $('#e<?php echo $subject_id; ?>').tooltip('show')
                                    $('#e<?php echo $subject_id; ?>').tooltip('hide')
                                });
                            </script>
                            <!-- end script -->

                                <tr class="odd gradeX">

                                    <td><?php echo $row['subject_code']; ?></td> 
                                    <td><?php echo $row['subject_title']; ?></td> 

                                    <td width="50">
                                        <a rel="tooltip"  title="Delete Subject" id="d<?php echo $subject_id; ?>" href="#id<?php echo $id; ?>" role="button"  data-toggle="modal" class="btn btn-danger"><i class="icon-trash icon-large"></i>&nbsp;</a>

                                    </td>
                                    <!-- user delete modal -->
                            <div id="id<?php echo $id; ?>" class="modal hide fade" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
                                <div class="modal-header">
                                </div>
                                <div class="modal-body">
                                    <div class="alert alert-danger">Are you Sure you Want to <strong>Delete</strong>&nbsp; this Subject?</div>
                                </div>
                                <div class="modal-footer">
                                    <button class="btn" data-dismiss="modal" aria-hidden="true"><i class="icon-remove icon-large"></i>&nbsp;Close</button>
                                    <a href="delete_teacher_course.php<?php echo '?id=' . $course_id; ?>" class="btn btn-danger"><i class="icon-trash icon-large"></i>&nbsp;Delete</a>
                                </div>
                            </div>
                            <!-- end delete modal -->

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

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


</body>
</html>

navhead_user.php

<div class="row-fluid">
    <div class="span12">


        <div class="navbar navbar-fixed-top navbar-inverse">
            <div class="navbar-inner">
                <div class="container">

                    <!-- .btn-navbar is used as the toggle for collapsed navbar content -->
                    <a class="btn btn-navbar" data-toggle="collapse" data-target=".nav-collapse">
                        <span class="icon-bar"></span>
                        <span class="icon-bar"></span>
                        <span class="icon-bar"></span>
                    </a>

                    <!-- Be sure to leave the brand out there if you want it shown -->


                    <!-- Everything you want hidden at 940px or less, place within here -->



                    <div class="nav-collapse collapse">
                        <!-- .nav, .navbar-search, .navbar-form, etc -->
                       <i class="icon-facebook-sign icon-large" id="color_white"></i>
                        <i class="icon-twitter icon-large" id="color_white"></i>
                        <i class="icon-google-plus icon-large" id="color_white"></i>
                        <i class="icon-github-alt icon-large" id="color_white"></i>
                        <i class="icon-linkedin-sign icon-large" id="color_white"></i>
                        <div class="pull-right">
                            <form class="navbar-search pull-left">

                                <i class="icon-search icon-large" id="color_white"></i>
                                <input type="text" class="search-query" placeholder="Search">
                            </form>
                        </div>

                        <!-- end collapse -->
                    </div>

                </div>
            </div>
        </div>
        <div class="hero-unit-header">
            <div class="container">

                <div class="row-fluid">
                    <div class="span12">
                        <div class="row-fluid">
                            <div class="span6">
                             <img src="admin/images/head.png">

                            </div>
                            <div class="span6">
                                <div class="pull-right">
                                    <!--- login button -->                           
                                  <?php 
                                    $student_query=mysql_query("select * from teacher where teacher_id='$session_id'")or die(mysql_error());
                                    $teacher_row=  mysql_fetch_array($student_query);
                                    ?>

                                     <img  src="admin/<?php echo $teacher_row['location']; ?>"  class="img img-rounded" id="picture">
                                        &nbsp;
                                    <div class="btn-group">

                                        <button class="btn btn-success"><i class="icon-user icon-large"></i>&nbsp; <?php echo $user_row['firstname'] . " " . $user_row['lastname']; ?></button>
                                        <button class="btn dropdown-toggle" data-toggle="dropdown">
                                            <span class="caret"></span>
                                        </button>
                                        <ul class="dropdown-menu">
                                            <li><a href="#logout" role="button"  data-toggle="modal"><i class="icon-signout icon-large"></i>&nbsp;Logout</a></li>
                                        </ul>

                                    </div>

                                    <?php include('logout_modal.php') ?>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>

            </div>
        </div>
Member Avatar for diafol

Your problem - from a quick scan - is that you have html output before the header() statement. This is the problem when you mix php and html. All your processing should be done above the DTD and then just simple echoes (or the odd loop/conditional) in your html area.

hey acquilina can you please send me the whole project and i guarantee you success i have followed all your querries and i think i can help you
email is chiwawanyeriasis@gmail.com

Member Avatar for diafol

You're 8 months too late.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.