As the title states, I'm trying to send html form checkbox data (that is supposed to query a MySQL database) to a PHP script where the output should be a table of the queries' results. I have one document for the html and another for the php/sql. The query works fine in MySQL but when I try executing it through html/php, I get column names for the results table but no queried results. This is THE problem.
The database groups users into groups and groups into departments. The query finds user vacancies (where user_id=1) within departments. I imagine it's the php that's screwing me up. Here's what I have so far--
The html form:
<form name="dept_checkbox" method="post" action="dept.php">
<fieldset>
<legend>In which department would like to find open positions?</legend><br />
<input type="checkbox" name="dept_name" id="dept_name" value="First Department" />First Department<br />
<input type="checkbox" name="dept_name" id="dept_name" value="Second Department" />Second Department<br />
<input type="checkbox" name="dept_name" id="dept_name" value="Third Department" />Third Department<br />
<input type="checkbox" name="dept_name" id="dept_name" value="Fourth Department" />Fourth Department<br />
<input type="checkbox" name="dept_name" id="dept_name" value="Fifth Department" />Fifth Department<br />
<input type="checkbox" name="dept_name" id="dept_name" value="All Departments"/>All Departments<br /><br />
<input type="submit" value="Submit" />
</fieldset>
The above displays fine in the browser. The following is my failed attempt to run the sql query through php. At this point, i'm just trying to get it to work for one department ("First Department") and, once I get that to work, I figure I can go from there. Here's the sql/php minus the database login info at the beginning of the script:
if(isset($POST[dept_name])){
$sql="select user_role,group_name
from groups,users,groups_users_link,departments
where groups.group_id=groups_users_link.groups_id
and users.user_id=groups_users_link.user_id
and groups.department_id=departments.department_id
and league_name like \"First Department\"
and groups_users_link.user_id=1";
$result=mysql_query($sql);
}
Let me reiterate that the above query is working in MySQL. The following is the rest of the php script which is supposed to display the results in table form:
echo("<table border=\"10px\">");
echo("<tr><th>Role</th><th>Group</th></tr>");
while($myrow=mysql_fetch_array($result))
{
echo("<tr><td>".$myrow[user_role]."</td>");
echo("<td>".$myrow[group_name]."</td>");
}
echo("</table>");
?>
<h4><a href="dept.html">Back to form</a></h4>
I'm wanting this to display all the vacant user roles for such-and-such groups within the department "First Department." Instead it displays the column names but the query results are missing. Any help would be greatly appreciated.