We help IT Professionals succeed at work.
Get Started

Post form to itself with 2D array of check boxes

CDirenzi
CDirenzi asked
on
564 Views
Last Modified: 2013-12-12
I have a MySQL table called projects that has 9 fields; a building name and 8 different types of projects for the building.  I am trying to create a page with a check box for every project type for each building.  The image below shows that table that is properly displaying from the database.  

I am trying to have this form post to itself, and when it loads save the checks to the database.  I am really having trouble with this, because I can't keep my names correct.  I think my problem is that I don't fully understand how the check boxes work- I'm not very experienced with web programming.  

I've attached my code, what exactly do I need to include at the top to get the results from the post, update the database, and then display the updated checks?  

Thanks!!!
<?


session_start();
if($_SESSION['auth']!="yes")
	{
	header("Location: index.php");
	exit();
	}

$username = $_SESSION['username'];

include("SQLLogin.inc");


// H E R E   I  S   W H E R E   I    N E E D    T O   A D D   C O D E 



?>


<head>
<meta http-equiv="Content-Type" content="text/html; charset=windows-1252">
</head>

<body>


<? //include("header.inc");  ?>


<form method="post" action="home.php"> <p>


<? 


$query = "SELECT * FROM projects ORDER BY 'order' ";
$result = mysql_query($query) or die ("Could not access the database to read directory");
echo "<table cellspacing='0' cellpadding='0' width='100%' border='0'>	";

$count = 1;

?>

<tr bgcolor='#bfc2ff' >
	<td>
		Building
	</td>
	<td>
		HVAC
	</td>
	<td>
		HVAC
	</td>
	<td>
		Light
	</td>
	<td>
		Envelope
	</td>
	<td>
		Water
	</td>
	<td>
		Special
	</td>
	<td>
		ECM
	</td>
	<td>
		Report
	</td>
	<td>
		Percent
	</td>
	<td>
		Notes
	</td>
</tr>

<?

while($row=mysql_fetch_array($result))
	{
	extract($row);

	if($count % 2 == 0)
		$color ='#bfe2f9';
	else
		$color = '#ECF7FD';
	?>

	<tr bgcolor="<? echo $color; ?>" >
	<td>
		<? echo $building; ?>
	</td>
	<td>
		<input type="checkbox" name="<? echo $ID; ?>" value="hvacA" />
	</td>
	<td>
		<input type="checkbox" name="<? echo $ID; ?>" value="hvacB" />
	</td>
	<td>
		<input type="checkbox" name="<? echo $ID; ?>" value="Light" />
	</td>
	<td>
		<input type="checkbox" name="<? echo $ID; ?>" value="Envelope" />
	</td>
	<td>
		<input type="checkbox" name="<?  echo $ID; ?>" value="Water" />
	</td>
	<td>
		<input type="checkbox" name="<?  echo $ID; ?>" value="Special" />
	</td>
	<td>
		<input type="checkbox" name="<?  echo $ID; ?>" value="ECM" />
	</td>
	<td>
		<input type="checkbox" name="<?  echo $ID; ?>" value="Report" />
	</td>
	<td>
		<input type="checkbox" name="<?  echo $ID; ?>" value="Percent" />
	</td>
	<td>
		<input type="checkbox" name="<?  echo $ID; ?>" value="Notes" />
	</td>
</tr>

<?
	$count = $count + 1;
	}

?>

</table>

<p align="center">
<input type = hidden name = "passedUser" value ="<? echo '$username'; ?>" />
<input type="submit" name="submit" value="Save Changes"/></p>

	</font>
	<p align="center">

&nbsp;</p>
</p> </form>

</body>



<?
mysql_close($connection);
?>

Open in new window

image.JPG
Comment
Watch Question
This problem has been solved!
Unlock 2 Answers and 7 Comments.
See Answers
Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

  • Troubleshooting
  • Research
  • Professional Opinions
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE