0

I have been trying to use a MySQLi->prepare statement to query a database and then echo the results onto another page in my site. I have been able to get this to work and display the results onto the same page as the query but not able to put the results onto the other webpage. Please help.. Here is my code.

Here is the code for the process page:

    <?php
    include_once 'db_connect.php';
    include_once 'psl-config.php';
    include_once 'functions.php';
    sec_session_start();

    $error_msg = "";

    if (isset($_GET['subject']))
    $subject = $_GET['subject'];
    if (isset($_GET['set_date']))
    $set_date = $_GET['set_date'];
if (isset($_GET['set_time']))
$set_time = $_GET['set_time'];
if (isset($_GET['result']))
$result = $_GET['result'];
if (isset($_GET['employee']))
$employee = $_GET['employee'];
if (isset($_GET['project']))
$employee = $_GET['project'];
if (isset($_GET['source']))
$source = $_GET['source'];
if (isset($_GET['appt_date']))
$appt_date = $_GET['appt_date'];
if (isset($_GET['branch']))
$branch = $_GET['branch'];
if (isset($_GET['fname']))
$fname = $_GET['fname'];
if (isset($_GET['lname']))
$lname = $_GET['lname'];
if (isset($_GET['last_four']))
$last_four = $_GET['last_four'];
if (isset($_GET['phone']))
$phone = $_GET['phone'];
if (isset($_GET['city']))
$city = $_GET['city'];
if (isset($_GET['state']))
$state = $_GET['state'];
if (isset($_GET['zip']))
$zip = $_GET['zip'];
if (isset($_GET['monthly_net']))
$monthly_net = $_GET['monthly_net'];
if (isset($_GET['job_time']))
$job_time = $_GET['job_time'];

$query = $mysqli->prepare("SELECT subject, set_date, set_time, result, employee, project, source, appt_date, branch, fname, lname, last_four, phone, city, state, zip, monthly_net, job_time FROM appointments WHERE set_date LIKE CONCAT('%', ?, '%') AND result LIKE CONCAT('%', ?, '%') AND employee LIKE CONCAT('%', ?, '%') AND project LIKE CONCAT('%', ?, '%') AND source LIKE CONCAT('%', ?, '%') AND appt_date LIKE CONCAT('%', ?, '%') AND branch LIKE CONCAT('%', ?, '%') AND fname LIKE CONCAT('%', ?, '%') AND lname LIKE CONCAT('%', ?, '%') AND last_four LIKE CONCAT('%', ?, '%') AND phone LIKE CONCAT('%', ?, '%') AND city LIKE CONCAT('%', ?, '%') AND state LIKE CONCAT('%', ?, '%') AND zip LIKE CONCAT('%', ?, '%') ORDER BY employee");
$query->bind_param('ssssssssssssss', $_GET['set_date'], $_GET['result'], $_GET['employee'], $_GET['project'], $_GET['source'], $_GET['appt_date'], $_GET['branch'], $_GET['fname'], $_GET['lname'], $_GET['last_four'], $_GET['phone'], $_GET['city'], $_GET['state'], $_GET['zip']);
$query->execute();
$query->store_result();
$query->bind_result($subject, $set_date, $set_time, $result, $employee, $project, $source, $appt_date, $branch, $fname, $lname, $last_four, $phone, $city, $state, $zip, $monthly_net, $job_time);
while($results = $query->fetch()) {
    $subject = $results['subject'];
    $set_date = $results['set_date'];
    $set_time = $results['set_time'];
    $result = $results['result'];
    $employee = $results['employee'];
    $project = $results['project'];
    $source = $results['source'];
    $appt_date = $results['appt_date'];
    $branch = $results['branch'];
    $fname = $results['fname'];
    $lname = $results['lname'];
    $last_four = $results['last_four'];
    $phone = $results['phone'];
    $city = $results['city'];
    $state = $results['state'];
    $zip = $results['zip'];
    $monthly_net = $results['monthly_net'];
    $job_time = $results['job_time'];
}
$_SESSION['subject'] = $subject;
$_SESSION['set_date'] = $set_date;
$_SESSION['set_time'] = $set_time;
$_SESSION['result'] = $result;
$_SESSION['employee'] = $employee;
$_SESSION['project'] = $project;
$_SESSION['source'] = $source;
$_SESSION['appt_date'] = $appt_date;
$_SESSION['branch'] = $branch;
$_SESSION['fname'] = $fname;
$_SESSION['lname'] = $lname;
$_SESSION['last_four'] = $last_four;
$_SESSION['phone'] = $phone;
$_SESSION['city'] = $city;
$_SESSION['state'] = $state;
$_SESSION['zip'] = $zip;
$_SESSION['monthly_net'] = $monthly_net;
$_SESSION['job_time'] = $job_time;
if ($_SESSION['employee']) {
        header('Location: ../appointments_page.php');
    } else {
        header('Location: ../appointments.php?error=1');
    }

$query->free_result();
$mysqli->close();
?>

And Here is the code to the page I want to display the results:

<?php
include_once 'includes/db_connect.php';
include_once 'includes/functions.php';
include_once 'includes/appointments.inc.php';
sec_session_start();
?>

<!doctype html>
<html class="no-js" lang="en">
    <head>
        <meta charset="utf-8">
        <meta http-equiv="x-ua-compatible" content="ie=edge">
        <title>Welcome | Mountain and Alpine Loan Centers</title>
        <meta name="description" content="Mountain and Alpine Loan Centers">
        <meta name="viewport" content="width=device-width, initial-scale=1">

        <link rel="apple-touch-icon" href="apple-touch-icon.png">
        <!-- Place favicon.ico in the root directory -->

        <link rel="stylesheet" href="css/normalize.css">
        <link rel="stylesheet" href="css/main.css">
        <script src="js/vendor/modernizr-2.8.3.min.js"></script>
        <script type="text/JavaScript" src="js/sha512.js"></script> 
        <script type="text/JavaScript" src="js/forms.js"></script> 
    </head>
    <body>
        <!--[if lt IE 8]>
            <p class="browserupgrade">You are using an <strong>outdated</strong> browser. Please <a href="http://browsehappy.com/">upgrade your browser</a> to improve your experience.</p>
        <![endif]-->

        <!-- Add your site or application content here -->
        <div align="center">
        <img src="../img/Logo4_Black_Red.jpg" height="126" width="266">
        <nav id="nav01"></nav></div>
        <div align="center"><br><br><br> 


            <?php 
            if(isset($_SESSION['subject']) && isset($_SESSION['set_date']) && isset($_SESSION['set_time']) && isset($_SESSION['result']) && isset($_SESSION['employee']) && isset($_SESSION['project']) && isset($_SESSION['source']) && isset($_SESSION['appt_date']) && isset($_SESSION['branch']) && isset($_SESSION['fname']) && isset($_SESSION['lname']) && isset($_SESSION['last_four']) && isset($_SESSION['phone']) && isset($_SESSION['city']) && isset($_SESSION['state']) && isset($_SESSION['zip']) && isset($_SESSION['monthly_net']) && isset($_SESSION['job_time'])) {
    echo "<table border='1'>";
    echo "<tr>";
    echo "<th>Subject</th>";
    echo "<th>Date Set</th>";
    echo "<th>Time Set</th>";
    echo "<th>Result</th>";
    echo "<th>Employee</th>";
    echo "<th>Project</th>";
    echo "<th>Source</th>";
    echo "<th>Appointment Date</th>";
    echo "<th>Branch</th>";
    echo "<th>First Name</th>";
    echo "<th>Last Name</th>";
    echo "<th>Last Four</th>";
    echo "<th>Phone</th>";
    echo "<th>City</th>";
    echo "<th>State</th>";
    echo "<th>Zip</th>";
    echo "<th>Monthly Net</th>";
    echo "<th>Time at Job</th>";
    echo "</tr>";

            for($i=0;$i<count($_SESSION['subject']);$i++) {

        echo "<tr>";
        echo "<td>{$_SESSION['subject'][$i]}</td>";
        echo "<td>{$_SESSION['set_date'][$i]}</td>";
        echo "<td>{$_SESSION['set_time'][$i]}</td>";
        echo "<td>{$_SESSION['result'][$i]}</td>";
        echo "<td>{$_SESSION['employee'][$i]}</td>";
        echo "<td>{$_SESSION['project'][$i]}</td>";
        echo "<td>{$_SESSION['source'][$i]}</td>";
        echo "<td>{$_SESSION['appt_date'][$i]}</td>";
        echo "<td>{$_SESSION['branch'][$i]}</td>";
        echo "<td>{$_SESSION['fname'][$i]}</td>";
        echo "<td>{$_SESSION['lname'][$i]}</td>";
        echo "<td>{$_SESSION['last_four'][$i]}</td>";
        echo "<td>{$_SESSION['phone'][$i]}</td>";
        echo "<td>{$_SESSION['city'][$i]}</td>";
        echo "<td>{$_SESSION['state'][$i]}</td>";
        echo "<td>{$_SESSION['zip'][$i]}</td>";
        echo "<td>{$_SESSION['monthly_net'][$i]}</td>";
        echo "<td>{$_SESSION['job_time'][$i]}</td>";
        echo "</tr>";
        echo "</table>";
            }

}else{

    echo "No Records Found";
}

 ?>

            <p>Return to the<a href="index.php">login page</a></p>
        </div>


        <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script>
        <script>window.jQuery || document.write('<script src="js/vendor/jquery-1.11.3.min.js"><\/script>')</script>
        <script src="js/plugins.js"></script>
        <script src="js/main.js"></script>
        <script src="../js/script.js"></script>

        <!-- Google Analytics: change UA-XXXXX-X to be your site's ID. -->
        <script>
            (function(b,o,i,l,e,r){b.GoogleAnalyticsObject=l;b[l]||(b[l]=
            function(){(b[l].q=b[l].q||[]).push(arguments)});b[l].l=+new Date;
            e=o.createElement(i);r=o.getElementsByTagName(i)[0];
            e.src='https://www.google-analytics.com/analytics.js';
            r.parentNode.insertBefore(e,r)}(window,document,'script','ga'));
            ga('create','UA-XXXXX-X','auto');ga('send','pageview');
        </script>
    </body>
</html>

UPDATE: I have made the changes that have been suggested but am getting sent to my 'else' error page. I know the query I'm running brought back and displayed results when I was displaying them on the same page as the query.

Here is the new code for the Processing Page

<?php
include_once 'db_connect.php';
include_once 'psl-config.php';
include_once 'functions.php';
sec_session_start();

$error_msg = "";

if (isset($_GET['subject']))
$subject = $_GET['subject'];
if (isset($_GET['set_date']))
$set_date = $_GET['set_date'];
if (isset($_GET['set_time']))
$set_time = $_GET['set_time'];
if (isset($_GET['result']))
$result = $_GET['result'];
if (isset($_GET['employee']))
$employee = $_GET['employee'];
if (isset($_GET['project']))
$employee = $_GET['project'];
if (isset($_GET['source']))
$source = $_GET['source'];
if (isset($_GET['appt_date']))
$appt_date = $_GET['appt_date'];
if (isset($_GET['branch']))
$branch = $_GET['branch'];
if (isset($_GET['fname']))
$fname = $_GET['fname'];
if (isset($_GET['lname']))
$lname = $_GET['lname'];
if (isset($_GET['last_four']))
$last_four = $_GET['last_four'];
if (isset($_GET['phone']))
$phone = $_GET['phone'];
if (isset($_GET['city']))
$city = $_GET['city'];
if (isset($_GET['state']))
$state = $_GET['state'];
if (isset($_GET['zip']))
$zip = $_GET['zip'];
if (isset($_GET['monthly_net']))
$monthly_net = $_GET['monthly_net'];
if (isset($_GET['job_time']))
$job_time = $_GET['job_time'];

$query = $mysqli->prepare("SELECT subject, set_date, set_time, result, employee, project, source, appt_date, branch, fname, lname, last_four, phone, city, state, zip, monthly_net, job_time FROM appointments WHERE set_date LIKE CONCAT('%', ?, '%') AND result LIKE CONCAT('%', ?, '%') AND employee LIKE CONCAT('%', ?, '%') AND project LIKE CONCAT('%', ?, '%') AND source LIKE CONCAT('%', ?, '%') AND appt_date LIKE CONCAT('%', ?, '%') AND branch LIKE CONCAT('%', ?, '%') AND fname LIKE CONCAT('%', ?, '%') AND lname LIKE CONCAT('%', ?, '%') AND last_four LIKE CONCAT('%', ?, '%') AND phone LIKE CONCAT('%', ?, '%') AND city LIKE CONCAT('%', ?, '%') AND state LIKE CONCAT('%', ?, '%') AND zip LIKE CONCAT('%', ?, '%') ORDER BY employee");
$query->bind_param('ssssssssssssss', $_GET['set_date'], $_GET['result'], $_GET['employee'], $_GET['project'], $_GET['source'], $_GET['appt_date'], $_GET['branch'], $_GET['fname'], $_GET['lname'], $_GET['last_four'], $_GET['phone'], $_GET['city'], $_GET['state'], $_GET['zip']);
$query->execute();
$query->store_result();
$query->bind_result($subject, $set_date, $set_time, $result, $employee, $project, $source, $appt_date, $branch, $fname, $lname, $last_four, $phone, $city, $state, $zip, $monthly_net, $job_time);
$results = array();
while($row = $query->fetch()) {
    $results = $row;
}
$_SESSION['results'] = $results;
if ($results) {
        header('Location: ../appointments_page.php');
    } else {
        header('Location: ../appointments.php?error=1');
    }

$query->free_result();
$mysqli->close();
?>

And the new code for the Display Page:

<?php
include_once 'includes/db_connect.php';
include_once 'includes/functions.php';
include_once 'includes/appointments.inc.php';
sec_session_start();
?>

<!doctype html>
<html class="no-js" lang="en">
    <head>
        <meta charset="utf-8">
        <meta http-equiv="x-ua-compatible" content="ie=edge">
        <title>Welcome | Mountain and Alpine Loan Centers</title>
        <meta name="description" content="Mountain and Alpine Loan Centers">
        <meta name="viewport" content="width=device-width, initial-scale=1">

        <link rel="apple-touch-icon" href="apple-touch-icon.png">
        <!-- Place favicon.ico in the root directory -->

        <link rel="stylesheet" href="css/normalize.css">
        <link rel="stylesheet" href="css/main.css">
        <script src="js/vendor/modernizr-2.8.3.min.js"></script>
        <script type="text/JavaScript" src="js/sha512.js"></script> 
        <script type="text/JavaScript" src="js/forms.js"></script> 
    </head>
    <body>
        <!--[if lt IE 8]>
            <p class="browserupgrade">You are using an <strong>outdated</strong> browser. Please <a href="http://browsehappy.com/">upgrade your browser</a> to improve your experience.</p>
        <![endif]-->

        <!-- Add your site or application content here -->
        <div align="center">
        <img src="../img/Logo4_Black_Red.jpg" height="126" width="266">
        <nav id="nav01"></nav></div>
        <div align="center"><br><br><br> 


            <?php 
            $results = $_SESSION['results'];
         if($results) {
    echo "<table border='1'>";
    echo "<tr>";
    echo "<th>Subject</th>";
    echo "<th>Date Set</th>";
    echo "<th>Time Set</th>";
    echo "<th>Result</th>";
    echo "<th>Employee</th>";
    echo "<th>Project</th>";
    echo "<th>Source</th>";
    echo "<th>Appointment Date</th>";
    echo "<th>Branch</th>";
    echo "<th>First Name</th>";
    echo "<th>Last Name</th>";
    echo "<th>Last Four</th>";
    echo "<th>Phone</th>";
    echo "<th>City</th>";
    echo "<th>State</th>";
    echo "<th>Zip</th>";
    echo "<th>Monthly Net</th>";
    echo "<th>Time at Job</th>";
    echo "</tr>";


            foreach($_SESSION['results'] as $result) {

                echo "<tr>";
                echo "<td>{$result['subject']}</td>";
                echo "<td>{$result['set_date']}</td>";
                echo "<td>{$result['set_time']}</td>";
                echo "<td>{$result['result']}</td>";
                echo "<td>{$result['employee']}</td>";
                echo "<td>{$result['project']}</td>";
                echo "<td>{$result['source']}</td>";
                echo "<td>{$result['appt_date']}</td>";
                echo "<td>{$result['branch']}</td>";
                echo "<td>{$result['fname']}</td>";
                echo "<td>{$result['lname']}</td>";
                echo "<td>{$result['last_four']}</td>";
                echo "<td>{$result['phone']}</td>";
                echo "<td>{$result['city']}</td>";
                echo "<td>{$result['state']}</td>";
                echo "<td>{$result['zip']}</td>";
                echo "<td>{$result['monthly_net']}</td>";
                echo "<td>{$result['job_time']}</td>";
                echo "</tr>";

            }


}else{

    echo "No Records Found";
}


 ?>

            <p>Return to the<a href="index.php">login page</a></p>
        </div>


        <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script>
        <script>window.jQuery || document.write('<script src="js/vendor/jquery-1.11.3.min.js"><\/script>')</script>
        <script src="js/plugins.js"></script>
        <script src="js/main.js"></script>
        <script src="../js/script.js"></script>

        <!-- Google Analytics: change UA-XXXXX-X to be your site's ID. -->
        <script>
            (function(b,o,i,l,e,r){b.GoogleAnalyticsObject=l;b[l]||(b[l]=
            function(){(b[l].q=b[l].q||[]).push(arguments)});b[l].l=+new Date;
            e=o.createElement(i);r=o.getElementsByTagName(i)[0];
            e.src='https://www.google-analytics.com/analytics.js';
            r.parentNode.insertBefore(e,r)}(window,document,'script','ga'));
            ga('create','UA-XXXXX-X','auto');ga('send','pageview');
        </script>
    </body>
</html>

I'm not getting any 'errors' reported so I feel like I'm close to solving this.

UPDATE #2 - Still getting sent to the error page. Here is how the code looks now:

Process Page:

<?php
include_once 'db_connect.php';
include_once 'psl-config.php';
include_once 'functions.php';
sec_session_start();

$error_msg = "";

if (isset($_GET['subject']))
$subject = $_GET['subject'];
if (isset($_GET['set_date']))
$set_date = $_GET['set_date'];
if (isset($_GET['set_time']))
$set_time = $_GET['set_time'];
if (isset($_GET['result']))
$result = $_GET['result'];
if (isset($_GET['employee']))
$employee = $_GET['employee'];
if (isset($_GET['project']))
$employee = $_GET['project'];
if (isset($_GET['source']))
$source = $_GET['source'];
if (isset($_GET['appt_date']))
$appt_date = $_GET['appt_date'];
if (isset($_GET['branch']))
$branch = $_GET['branch'];
if (isset($_GET['fname']))
$fname = $_GET['fname'];
if (isset($_GET['lname']))
$lname = $_GET['lname'];
if (isset($_GET['last_four']))
$last_four = $_GET['last_four'];
if (isset($_GET['phone']))
$phone = $_GET['phone'];
if (isset($_GET['city']))
$city = $_GET['city'];
if (isset($_GET['state']))
$state = $_GET['state'];
if (isset($_GET['zip']))
$zip = $_GET['zip'];
if (isset($_GET['monthly_net']))
$monthly_net = $_GET['monthly_net'];
if (isset($_GET['job_time']))
$job_time = $_GET['job_time'];

$query = $mysqli->prepare("SELECT subject, set_date, set_time, result, employee, project, source, appt_date, branch, fname, lname, last_four, phone, city, state, zip, monthly_net, job_time FROM appointments WHERE set_date LIKE CONCAT('%', ?, '%') AND result LIKE CONCAT('%', ?, '%') AND employee LIKE CONCAT('%', ?, '%') AND project LIKE CONCAT('%', ?, '%') AND source LIKE CONCAT('%', ?, '%') AND appt_date LIKE CONCAT('%', ?, '%') AND branch LIKE CONCAT('%', ?, '%') AND fname LIKE CONCAT('%', ?, '%') AND lname LIKE CONCAT('%', ?, '%') AND last_four LIKE CONCAT('%', ?, '%') AND phone LIKE CONCAT('%', ?, '%') AND city LIKE CONCAT('%', ?, '%') AND state LIKE CONCAT('%', ?, '%') AND zip LIKE CONCAT('%', ?, '%') ORDER BY employee");
$query->bind_param('ssssssssssssss', $_GET['set_date'], $_GET['result'], $_GET['employee'], $_GET['project'], $_GET['source'], $_GET['appt_date'], $_GET['branch'], $_GET['fname'], $_GET['lname'], $_GET['last_four'], $_GET['phone'], $_GET['city'], $_GET['state'], $_GET['zip']);
$query->execute();
$query->store_result();
$query->bind_result($subject, $set_date, $set_time, $result, $employee, $project, $source, $appt_date, $branch, $fname, $lname, $last_four, $phone, $city, $state, $zip, $monthly_net, $job_time);
$results = array();
while($row = $query->fetch()) {
    $results[] = array(
    'subject' => $subject,
    'set_date' => $set_date,
    'set_time' => $set_time,
    'result' => $result,
    'employee' => $employee,
    'project' => $project,
    'source' => $source,
    'appt_date' => $appt_date,
    'branch' => $branch,
    'fname' => $fname,
    'lname' => $lname,
    'last_four' => $last_four,
    'phone' => $phone,
    'city' => $city,
    'state' => $state,
    'zip' => $zip,
    'monthly_net' => $monthly_net,
    'job_time' => $job_time
    );
}
$_SESSION['results'] = $results;
if ($results) {
        header('Location: ../appointments_page.php');
    } else {
        header('Location: ../appointments.php?error=1');
    }

$query->free_result();
$mysqli->close();
?> 

Display Page:

<?php
include_once 'includes/db_connect.php';
include_once 'includes/functions.php';
include_once 'includes/appointments.inc.php';
sec_session_start();
?>

<!doctype html>
<html class="no-js" lang="en">
    <head>
        <meta charset="utf-8">
        <meta http-equiv="x-ua-compatible" content="ie=edge">
        <title>Welcome | Mountain and Alpine Loan Centers</title>
        <meta name="description" content="Mountain and Alpine Loan Centers">
        <meta name="viewport" content="width=device-width, initial-scale=1">

        <link rel="apple-touch-icon" href="apple-touch-icon.png">
        <!-- Place favicon.ico in the root directory -->

        <link rel="stylesheet" href="css/normalize.css">
        <link rel="stylesheet" href="css/main.css">
        <script src="js/vendor/modernizr-2.8.3.min.js"></script>
        <script type="text/JavaScript" src="js/sha512.js"></script> 
        <script type="text/JavaScript" src="js/forms.js"></script> 
    </head>
    <body>
        <!--[if lt IE 8]>
            <p class="browserupgrade">You are using an <strong>outdated</strong> browser. Please <a href="http://browsehappy.com/">upgrade your browser</a> to improve your experience.</p>
        <![endif]-->

        <!-- Add your site or application content here -->
        <div align="center">
        <img src="../img/Logo4_Black_Red.jpg" height="126" width="266">
        <nav id="nav01"></nav></div>
        <div align="center"><br><br><br> 


            <?php 
            $results = $_SESSION['results'];
         if($results) {
    echo "<table border='1'>";
    echo "<tr>";
    echo "<th>Subject</th>";
    echo "<th>Date Set</th>";
    echo "<th>Time Set</th>";
    echo "<th>Result</th>";
    echo "<th>Employee</th>";
    echo "<th>Project</th>";
    echo "<th>Source</th>";
    echo "<th>Appointment Date</th>";
    echo "<th>Branch</th>";
    echo "<th>First Name</th>";
    echo "<th>Last Name</th>";
    echo "<th>Last Four</th>";
    echo "<th>Phone</th>";
    echo "<th>City</th>";
    echo "<th>State</th>";
    echo "<th>Zip</th>";
    echo "<th>Monthly Net</th>";
    echo "<th>Time at Job</th>";
    echo "</tr>";


            foreach($_SESSION['results'] as $result) {

                echo "<tr>";
                echo "<td>{$result['subject']}</td>";
                echo "<td>{$result['set_date']}</td>";
                echo "<td>{$result['set_time']}</td>";
                echo "<td>{$result['result']}</td>";
                echo "<td>{$result['employee']}</td>";
                echo "<td>{$result['project']}</td>";
                echo "<td>{$result['source']}</td>";
                echo "<td>{$result['appt_date']}</td>";
                echo "<td>{$result['branch']}</td>";
                echo "<td>{$result['fname']}</td>";
                echo "<td>{$result['lname']}</td>";
                echo "<td>{$result['last_four']}</td>";
                echo "<td>{$result['phone']}</td>";
                echo "<td>{$result['city']}</td>";
                echo "<td>{$result['state']}</td>";
                echo "<td>{$result['zip']}</td>";
                echo "<td>{$result['monthly_net']}</td>";
                echo "<td>{$result['job_time']}</td>";
                echo "</tr>";

            }


}else{

    echo "No Records Found";
}


 ?>

            <p>Return to the<a href="index.php">login page</a></p>
        </div>


        <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script>
        <script>window.jQuery || document.write('<script src="js/vendor/jquery-1.11.3.min.js"><\/script>')</script>
        <script src="js/plugins.js"></script>
        <script src="js/main.js"></script>
        <script src="../js/script.js"></script>

        <!-- Google Analytics: change UA-XXXXX-X to be your site's ID. -->
        <script>
            (function(b,o,i,l,e,r){b.GoogleAnalyticsObject=l;b[l]||(b[l]=
            function(){(b[l].q=b[l].q||[]).push(arguments)});b[l].l=+new Date;
            e=o.createElement(i);r=o.getElementsByTagName(i)[0];
            e.src='https://www.google-analytics.com/analytics.js';
            r.parentNode.insertBefore(e,r)}(window,document,'script','ga'));
            ga('create','UA-XXXXX-X','auto');ga('send','pageview');
        </script>
    </body>
</html>

UPDATE #3 - The results display but on the Process Page and not the Display Page when I use var_dump($results).

Process Page (version 3):

<?php
include_once 'db_connect.php';
include_once 'psl-config.php';
include_once 'functions.php';
sec_session_start();

$error_msg = "";

if (isset($_GET['subject']))
$subject = $_GET['subject'];
if (isset($_GET['set_date']))
$set_date = $_GET['set_date'];
if (isset($_GET['set_time']))
$set_time = $_GET['set_time'];
if (isset($_GET['result']))
$result = $_GET['result'];
if (isset($_GET['employee']))
$employee = $_GET['employee'];
if (isset($_GET['project']))
$employee = $_GET['project'];
if (isset($_GET['source']))
$source = $_GET['source'];
if (isset($_GET['appt_date']))
$appt_date = $_GET['appt_date'];
if (isset($_GET['branch']))
$branch = $_GET['branch'];
if (isset($_GET['fname']))
$fname = $_GET['fname'];
if (isset($_GET['lname']))
$lname = $_GET['lname'];
if (isset($_GET['last_four']))
$last_four = $_GET['last_four'];
if (isset($_GET['phone']))
$phone = $_GET['phone'];
if (isset($_GET['city']))
$city = $_GET['city'];
if (isset($_GET['state']))
$state = $_GET['state'];
if (isset($_GET['zip']))
$zip = $_GET['zip'];
if (isset($_GET['monthly_net']))
$monthly_net = $_GET['monthly_net'];
if (isset($_GET['job_time']))
$job_time = $_GET['job_time'];

$query = $mysqli->prepare("SELECT subject, set_date, set_time, result, employee, project, source, appt_date, branch, fname, lname, last_four, phone, city, state, zip, monthly_net, job_time FROM appointments WHERE set_date LIKE CONCAT('%', ?, '%') AND result LIKE CONCAT('%', ?, '%') AND employee LIKE CONCAT('%', ?, '%') AND project LIKE CONCAT('%', ?, '%') AND source LIKE CONCAT('%', ?, '%') AND appt_date LIKE CONCAT('%', ?, '%') AND branch LIKE CONCAT('%', ?, '%') AND fname LIKE CONCAT('%', ?, '%') AND lname LIKE CONCAT('%', ?, '%') AND last_four LIKE CONCAT('%', ?, '%') AND phone LIKE CONCAT('%', ?, '%') AND city LIKE CONCAT('%', ?, '%') AND state LIKE CONCAT('%', ?, '%') AND zip LIKE CONCAT('%', ?, '%') ORDER BY employee");
$query->bind_param('ssssssssssssss', $_GET['set_date'], $_GET['result'], $_GET['employee'], $_GET['project'], $_GET['source'], $_GET['appt_date'], $_GET['branch'], $_GET['fname'], $_GET['lname'], $_GET['last_four'], $_GET['phone'], $_GET['city'], $_GET['state'], $_GET['zip']);
$query->execute();
$query->store_result();
$query->bind_result($subject, $set_date, $set_time, $result, $employee, $project, $source, $appt_date, $branch, $fname, $lname, $last_four, $phone, $city, $state, $zip, $monthly_net, $job_time);
$results = array();
while($row = $query->fetch()) {
    $results[] = array(
    'subject' => $subject,
    'set_date' => $set_date,
    'set_time' => $set_time,
    'result' => $result,
    'employee' => $employee,
    'project' => $project,
    'source' => $source,
    'appt_date' => $appt_date,
    'branch' => $branch,
    'fname' => $fname,
    'lname' => $lname,
    'last_four' => $last_four,
    'phone' => $phone,
    'city' => $city,
    'state' => $state,
    'zip' => $zip,
    'monthly_net' => $monthly_net,
    'job_time' => $job_time
    );
}
$_SESSION['results'] = $results;
if($results) {
        var_dump($results); 
        header('Location: ../appointments_page.php');
    } else {
        header('Location: ../appointments.php?error=1');
    }

$query->free_result();
$mysqli->close();
?>
Derek
  • 27
  • 4

2 Answers2

1

The problem is that you didn't create arrays in the process page. Your while loop overwrites the variables like $subject each time, it doesn't append the current values to an array. It should be:

$_SESSION['subject'] = array();
$_SESSION['set_date'] = array();
...
while($results = $query->fetch()) {
    $_SESSION['subject'][] = $subject;
    $_SESSION['set_date'][] = $set_date;
    ...
}

However, I wouldn't use separate variables for each column, I'd just collect everything into a multi-dimensional array:

$results = array();
while ($row = $query->fetch()) {
    $results[] = array(
        'subject' => $subject,
        'set_date' => $set_date,
        'set_time' => $set_time,
        'result' => $result,
        'employee' => $employee,
        'project' => $project,
        'source' => $source,
        'appt_date' => $appt_date,
        'branch' => $branch,
        'fname' => $fname,
        'lname' => $lname,
        'last_four' => $last_four,
        'phone' => $phone,
        'city' => $city,
        'state' => $state,
        'zip' => $zip,
        'monthly_net' => $monthly_net,
        'job_time' => $job_time
    );
}
$_SESSION['results'] = $results;

Then in the display page, it would be:

foreach ($_SESSION['results'] as $result) {
    echo "<tr>";
    echo "<td>{$result['subject']}</td>";
    echo "<td>{$result['set_date']}</td>";
    echo "<td>{$result['set_time']}</td>";
    echo "<td>{$result['result']}</td>";
    echo "<td>{$result['employee']}</td>";
    echo "<td>{$result['project']}</td>";
    echo "<td>{$result['source']}</td>";
    echo "<td>{$result['appt_date']}</td>";
    echo "<td>{$result['branch']}</td>";
    echo "<td>{$result['fname']}</td>";
    echo "<td>{$result['lname']}</td>";
    echo "<td>{$result['last_four']}</td>";
    echo "<td>{$result['phone']}</td>";
    echo "<td>{$result['city']}</td>";
    echo "<td>{$result['state']}</td>";
    echo "<td>{$result['zip']}</td>";
    echo "<td>{$result['monthly_net']}</td>";
    echo "<td>{$result['job_time']}</td>";
    echo "</tr>";
}

Also, echo "</table>"; should not be in the loop in the display script. The loop just processes each row.

Barmar
  • 741,623
  • 53
  • 500
  • 612
  • Sidenote: shouldn't `echo "";` be outside the loop? – Funk Forty Niner Jun 30 '15 at 18:55
  • Good point, I just copied that from the original without even noticing it. – Barmar Jun 30 '15 at 18:58
  • The `foreach ($_SESSION['results'] as $result)` makes for a better method too. *Good show* ;-) – Funk Forty Niner Jun 30 '15 at 18:59
  • I've made the changes but I'm getting sent to the appointments.php?error=1 page. – Derek Jun 30 '15 at 19:48
  • Which version of the changes did you use, separate variables for each column or one variable for everything? – Barmar Jun 30 '15 at 19:54
  • Barmar, I used the one variable for everything – Derek Jun 30 '15 at 19:55
  • Then I don't see how that can happen. Even if there are no results, `if ($results)` will succeed, because an empty array is truthy. – Barmar Jun 30 '15 at 19:55
  • Oh, you're using `bind_result`, not `fetch_assoc`. So `$query->fetch()` doesn't return the row. I'll show the corrected answer. – Barmar Jun 30 '15 at 19:58
  • I was also missing `[]` in the `$results` assignment, so it wasn't appending to the array. – Barmar Jun 30 '15 at 20:02
  • Barmar will your corrected answer be an answer on this post? – Derek Jun 30 '15 at 20:08
  • Barmar, I made the changes you suggested but I still get sent to the error page. I have put the new updated code onto this again. I feel like it's just a small minor detail I'm missing and I'm right on the edge of figuring this out. Thanks so much for your help with this – Derek Jun 30 '15 at 20:26
  • I still don't see how that can happen. `$results` is an array, so `if ($results)` will ALWAYS be true, even if the query didn't return anything. What does `var_dump($results)` show? – Barmar Jun 30 '15 at 20:32
  • Barmar, I used var_dump and the results displayed but on the process page and not on the display page. I put newest version of the process page code on here. Super close now and this time no errors or error page – Derek Jun 30 '15 at 20:55
  • It's process page version 3 – Derek Jun 30 '15 at 20:55
  • Of course it displayed on the process page, isn't that where you did it? If you have output before `header()`, it prevents the redirect. – Barmar Jun 30 '15 at 21:00
  • This is making less and less sense. You put the `var_dump()` inside the `if` block (I expected you to put it **before** the `if`, since the point was to see what it was testing). Since it printed the `var_dump()` output, that means the `if` was successful, so it should have redirected to `appointments_page.php`, not `appointments.php?error=1`. – Barmar Jun 30 '15 at 21:03
  • When I put it before the 'if' then it goes to the error page, after the if it displays but on the process page. This query did display this correctly when on the process page from the beginning and I was trying to display the results onto a different page and that's what I can't get to work. Need to know where to put var_dump so that it dumps onto the display page and not the process page – Derek Jun 30 '15 at 21:16
  • But the problem you're having is that it's not going to the display page in the first place, and we're trying to figure out why that is. How would putting the var_dump() on the display page help if it's going to the error page?[ – Barmar Jun 30 '15 at 21:38
  • What I don't understand is how it could be doing the var_dump. You put that in the branch of the `if` that goes to the display page. But if you take the `var_dump` out of there, it executes the `else` branch` and goes to the error page. That's what makes no sense. Is there some other way to get to the error page besides that `if` in the process page? – Barmar Jun 30 '15 at 21:40
  • There is no other way to get to the error page besides the 'if'. But it does var_dump the $results array onto the same page when I replace the 'if'. The error on the display page is "No Results Found". I just can't figure out how to send the array data to my display page and have it display there. – Derek Jul 01 '15 at 16:34
  • How can you be seeing "No results found" if you go to the error page instead of the display page? That message is printed by the display page. – Barmar Jul 01 '15 at 17:31
  • What does `var_dump($_SESSION)` show on the display page? I suspect it's not starting the session properly. Try putting the call to `sec_session_start()` before all the `include_once` lines in all the scripts. – Barmar Jul 01 '15 at 17:34
  • @Barmar When I use 'var_dump($_SESSION)' It displays the array data on the process page and doesn't direct it to the display page. I've even tried to use just session_start() and same thing. Here is a small example of the results from 'var_dump($_SESSION)' – Derek Jul 01 '15 at 18:23
  • I asked what it shows if you put that on the display page. – Barmar Jul 01 '15 at 18:24
  • It's weird because when I remove the 'var_dump' from the process page and put it on the display page I get redirected to the 'error page' as if it's not finding $results but when I do have var_dump on the process page it displays the array correctly but on the process page and not redirecting the data to the display page. I'm just as confused as you are on this one – Derek Jul 01 '15 at 18:35
  • I'm sorry, I'm going to have to give up on this. There must be more going on than you're letting on, and I don't know the right questions to ask to find out what it is. – Barmar Jul 01 '15 at 18:38
  • I would to if I could. Thanks for your help @Barmar the code you gave me is probably correct I just need to get the order right or something. – Derek Jul 01 '15 at 18:49
  • @Barmar your code was correct and I was able to get this to work. Thanks again for solving my problem. I appreciate it – Derek Jul 01 '15 at 20:39
0

I was able to get the results to display correctly on the 'Display Page' by removing all the 'includes' at the top of the 'Display Page' and just have 'session_start()' and then '$results = $_SESSION['results']' underneath it. When it was just these two statements it worked.

Derek
  • 27
  • 4
  • One of those includes was probably producing output. The PHP error log should have had a warning about "Headers already sent". This prevents the redirect code from working. – Barmar Jul 01 '15 at 20:40
  • See http://stackoverflow.com/questions/8028957/how-to-fix-headers-already-sent-error-in-php – Barmar Jul 01 '15 at 20:41