1

I am using the session variable $_SESSION['staff_id'] to use as part of a condition in a query string. Just to see if the variable is working I set it to echo as the variable $wombat as seen in the code but instead it is empty. I don't know what I am doing incorrectly.

I have looked all over the place just to make sure my syntax is correct and to my knowledge it is.

<?php 
SESSION_START();
define('INCLUDE_CHECK',true);
if(isset($_SESSION['staff_id']))
$_SESSION['staff_id']=$wombat;
echo "'$wombat'";

// get the overall page header, including bootstrap and datatables libraries
// as well as the navbar menu for the top of the web page
require_once('task_assignment_header.php');

// load DB name and user credentials from single file for entire website
// this makes life easier later on
require_once('db_credentials.php');

?>
    <div class="container" style='margin-top:50px;'>

      <?php

        $StaffDBconnection = new mysqli($db_hostname, $db_username, $db_userpass, $db_dbname);

        // Check connection
        if (mysqli_connect_errno())
        {
        echo "Failed to connect to MySQL: " . mysqli_connect_error();
        exit; // end program execution here
        }

        $resultset = mysqli_query($StaffDBconnection,"select t1.project_id, t1.project_name, t1.activeproject, t2.task_id, t2.taskname,
                                                      t2.taskstatus, t2.project_id, t3.staff_id, t3.fName, t3.lName, t4.staff_id, t4.task_id
                                                      from projects t1, tasks t2, employee t3, emp_tasks t4
                                                      where t1.activeproject = 'open'
                                                      and t2.taskstatus = 'in progress'
                                                      and t1.project_id = t2.project_id 
                                                      and t2.task_id = t4.task_id
                                                      and t3.staff_id = t4.staff_id
                                                      and t3.staff_id=" .$_SESSION['staff_id']);










        echo "<br><br>"; // put in a couple of blank lines at top below menu

        // This div tag makes the table "responsive" on smaller screens
        // and it also controls the overall width of the table.
        // Note that its width class of col-xs-5 is the sum of the width
        // classes used in the column heading (th) tags within the table, itself.
        echo "<div class='table-responsive col-xs-6'>";
                        // main table of data
            echo "<table id='assigntable' cellpadding='0' cellspacing='0' border='0' class='table table-striped table-bordered'>";
            echo "<thead><tr><th class='col-lg-4'>Project Name</th><th class='col-sm-4'>Task Name</th><th class='col-sm-4'>Employee Name</th></tr></thead><tbody>";

            while($AssignRow = mysqli_fetch_array($resultset))
              {
              $tmpID = $AssignRow['task_id'];
              $tmpprojid = $AssignRow['project_id'];


              echo "<tr><td>" . $AssignRow['project_name'] . "</td>" 
                     . "<td>" . $AssignRow['taskname'] . "</td>" . "<td>" . $AssignRow['fName']." ". $AssignRow['lName']. "</td>" . "</td>" ."</tr>";
               }

            echo "</tbody></table>";
            // end of main table of data

        echo "</div>"; // close out the responsive table div

        mysqli_close($StaffDBconnection);

      ?>



    </div><!-- /.container -->

<?php  
require_once('bootstrap_stafftable_footer.php');
?>
7
  • I think the condition in if(isset($_SESSION['staff_id'])) should be flipped: if(isset($_SESSION['staff_id']) === false) else staff_id will never get a value. Commented Apr 29, 2014 at 16:21
  • Where is defined $wombat?Have you looked into your error log? Commented Apr 29, 2014 at 16:21
  • 2
    SESSION_START() should be lowercase sesssion_start() Commented Apr 29, 2014 at 16:25
  • When using mysqli you should be using parameterized queries and bind_param to add user data to your query. DO NOT use string interpolation to accomplish this because you will create severe SQL injection bugs. Commented Apr 29, 2014 at 16:29
  • 1
    As a general rule, please don't add "I need this by Friday", "urgent" or some other variation. Questions here are answered by volunteers very much at their own leisure. That said, there are plenty of people who can help here, so ask clear, well-researched questions and you'll not have a problem getting a quick answer. Commented Apr 29, 2014 at 16:31

1 Answer 1

1

Your assignment is invalid, also (I guess) you've forgotten to wrap your first if in braces.

session_start();
define('INCLUDE_CHECK',true);
if(isset($_SESSION['staff_id'])){
    $wombat = $_SESSION['staff_id'];
   echo "$wombat";
} else {
   echo "Undefined index 'staff_id'"; /*To check if $_SESSION['staff_id'] is not defined */
}
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.