I have been working with vba for several years and I have become fairly proficient in it. I am now trying to learn PhP as I'm building an intranet site for my work and I am stuck on something I feel should be fairly straight forward and easy. After two days of searching and attempting to code I have not been successful.
I am attempting to take the result from a drop down menu and bringning that information to another page so that I can use it in a query.
Page1 is working fine as it is giving me a drop down list from a MySQL database and showing me all available 'Platoons'.
<?php
session_Start()
?>
<html>
<head><title>Captain Selection</title></head>
<body>
<?php
$user="root";
$host="localhost";
$password="*******";
$database = "PerformanceReport";
$cxn = mysqli_connect($host,$user,$password,$database)
or die ("couldn't connect to server");
$query = "SELECT stafflist.PlatoonCaptain\n"
. "FROM stafflist\n"
. "GROUP BY stafflist.PlatoonCaptain LIMIT 0, 4 ";
$result = mysqli_query($cxn,$query)
or die ("Couldn't execute query.");
?>
<html>
<head><title>Captains</title></head>
<body>
<form action='Platoon.php' method='POST'>
<select name='PlatoonCaptain'>
<?php
while($row = mysqli_fetch_assoc($result))
{
extract($row);
echo "<option value='$SelectPlatoon'>$PlatoonCaptain</option>\n";
}
echo "$SelectPlatoon<br />";
?>
</select>
<input type='submit' value='Select the Captain' />
</form></body></html>
Page 2 is working fine when I am giving a value to the $PlatoonCaptain variable. On this page I would like to have the $_SESSION from page 1 to transfer to page 2 and automatically assign that variable to $PlatoonCaptain.
<?php
session_Start();
?>
<html>
<head><title>Staff List Query</title></head>
<body>
<?php
$user="root";
$host="localhost";
$password="*****"
$database = "PerformanceReport";
$cxn = mysqli_connect($host,$user,$password,$database)
or die ("couldn't connect to server");
$PlatoonCaptain = $_SESSION['SelectPlatoon'];
$sql = "SELECT stafflist.Platoon, stafflist.LastName, stafflist.FirstName, Count(performancereport.CallNumber) AS CountOfCallNumber, stafflist.PlatoonCaptain\n"
. "FROM performancereport INNER JOIN stafflist ON performancereport.OASIS = stafflist.OASIS\n"
. "GROUP BY stafflist.Platoon, stafflist.LastName, stafflist.FirstName, stafflist.PlatoonCaptain\n"
. "HAVING (((stafflist.PlatoonCaptain)= '$PlatoonCaptain'))\n"
. "ORDER BY stafflist.LastName";
Please keep in mind that I left the coding for $_SESSION which was my last attempt, therefore I am aware that, that portion of the code is not correct.
Any of your help is greatly appreciated. I am a fast learner and hope that this is an easy solution.