This is my main page where the user can choose a category from a drop down. I need that category selection to update my session variable so I can then send that variable to another php page execute a query and return the result in my div because I do not want the entire page reloading everything the users hits submit.
Main issue: I cannot figure out how to reset/set the session variable when a user clicks submit then push that session variable to the next page for processing and return that page results back into my div.
Mainpage.php
<?php
session_start();
if (isset($_POST['Submit'])) {
$_SESSION['ServiceOrders'] = $_POST['ServiceOrders'];
}
?>
<!DOCTYPE html>
<html>
<head>
<link rel='stylesheet' type='text/css' href='styles.css' />
<link rel="stylesheet" href="grid.css" type="text/css" />
<link rel="stylesheet" href="backgroundcss.css" type="text/css" />
<style>
form { width: 700px; }
label { float: left; width: 100px; }
input[type=text] { float: left; width: 200px; }
.clear { clear: both; height: 0; line-height: 0; }
.floatright { float: right; }
</style>
<script src='http://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js'></script>
<script type='text/javascript' src='menu_jquery.js'></script>
<script type="text/javascript" src="jquery-1.9.1.min.js"></script>
<script type="text/javascript" src="https://www.google.com/jsapi"></script>
<link rel="stylesheet" href="//code.jquery.com/ui/1.10.4/themes/smoothness/jquery-ui.css">
<script src="//code.jquery.com/jquery-1.10.2.js"></script>
<script src="//code.jquery.com/ui/1.10.4/jquery-ui.js"></script>
<script>
$(function() {
$( "#datepicker" ).datepicker();
});
$(function() {
$("#refresh").on("click", function() {
$("#mydiv").load("http://192.241.175.69/ServiceOrderReport.php");
return false;
})
})
</script>
</head>
<body class="container">
<br>
<div id='cssmenu'>
<ul>
</ul>
</div>
<br>
<form action="ServiceOrderReport.php" method="post">
<select name="ServiceOrders">
<option value="Network Error">Network Error</option>
<option value="Reverse Rotation Detected">Equipment Error</option>
<option value="Cover Off">Failure</option>
<input type="text" name="sdate"id="datepicker" >
<input type="submit" id ="refresh" value=" Submit " name ="Submit"/><br />
</select>
</form>
<div id="mydiv" class="grid_12 omega scroll">
</div>
<div class="grid_12 ">
<div id="TopBorder" class="grid_12">
<footer class="mainFooter">
<p>Copyright © 2014 <a href="http://test.com">test.com</a></p>
</footer>
</div>
</div>
</body>
</html>
This is my ServiceOrderReport.php page where I am attempting to push the session variable into the query then pull the results back to my my main.php page. It works perfectly if the session variable is random static variable that I set.
<?php
session_start();
?>
<html>
<head>
<link rel='stylesheet' type='text/css' href='styles.css' />
<link rel="stylesheet" href="grid.css" type="text/css" />
<link rel="stylesheet" href="backgroundcss.css" type="text/css" />
<style>
form { width: 700px; }
label { float: left; width: 100px; }
input[type=text] { float: left; width: 200px; }
.clear { clear: both; height: 0; line-height: 0; }
.floatright { float: right; }
</style>
<body class="container">
<?php
// Make a MySQL Connection
mysql_connect("localhost", "root", "23moon") or die(mysql_error());
mysql_select_db("BEI_ANALYTICS_META_DB") or die(mysql_error());
$ServiceOrders= $_SESSION["ServiceOrders"];
$result = mysql_query("Select ID,StreetNumber,StreetName,City,ZipCode,HardwareID,CreatedDate,ServiceOrderdesc
From ServiceOrders
Where ServiceOrderdesc = '$ServiceOrders'
order by CreatedDate,StreetName,StreetNumber limit 1000;")
or die(mysql_error());
echo '<table class="bordered">
<thead>
<tr>
<th scope="col">ID</th>
<th scope="col">HardwareID</th>
<th scope="col">StreetNumber</th>
<th scope="col">StreetName</th>
<th scope="col">City</th>
<th scope="col">ZipCode</th>
<th scope="col">CreatedDate</th>
<th scope="col">ServiceOrderdesc</th>
</tr>
</thead>
<tbody>';
// keeps getting the next row until there are no more to get
while($row = mysql_fetch_array( $result )) {
echo "<tr><td>";
echo $row['ID'];
echo "</td><td>";
echo $row['HardwareID'];
echo "</td><td>";
echo $row['StreetNumber'];
echo "</td><td>";
echo $row['StreetName'];
echo "</td><td>";
echo $row['City'];
echo "</td><td>";
echo $row['ZipCode'];
echo "</td><td>";
echo $row['CreatedDate'];
echo "</td><td>";
echo $row['ServiceOrderdesc'];
echo "</td></tr>";
}
echo "</tbody></table>";
?>
</body>
</html>