My checkbox don't stay checked help please (Not a normal checkbox)

Hi, can someone help me with my checkbox? I am not going to lie but this is a school project I have never learned php javascript or html before, i only learn visual studios and C language, i have 0 experience in these programing languages until i was given this project so i am trying my best to do it. Ok so i made a database in MySQL and already imported a table with 4 columns with heading of: “chemicals quantity location and controlled” in my program, i made every single row have a checkbox at the side(once i checked the checkbox and click submit, it would print it out on another php page so that the user can select which ever chemical he/she wants) i also had drop down list for filtering out checmicals which are controlled by a certain department, and a searchbar for searching a particular chemical. However when i clicked on lets say one of the options on the drop down list, and it does it’s work by only showing me which ever department i selected and displays out the chemicals with the info of it but once i checked the chemical and go back to the full list of chemical, the tick disappear. My checkbox is different from normal checkbox i saw online because i have a button on my other php page to add new chemicals into the database meaning i will have an unkown amount of chemicals so i cant type my checkbox to be like

cat

dog

mouse

donkey

horse

I have to use $count

Here’s my code:


<html>
<head>
	<div id="container" style="width:1400px;margin:0 auto;">
	<div id="header" style="background-color:rgb(150,150,255);">
	<h1 style="margin:auto;" align="center">Nanyang Polytechnic</h1>
	<h3 style="margin:auto;" align="center">Chemical Inventory Management System</h3>
	</div>

		<script language='JavaScript'>
		<!--"checked" is false at default-->
		checked = false;								 function checkedAll ()
		{
			      if (checked == false)
			     {
				checked = true
			     }
		                   else
			     {
			              checked = false
			     }
                                   for (var i = 0; i < document.getElementById('myform').elements.length; i++) 
			{
			    document.getElementById('myform').elements[i].checked = checked;
			}
	              }
		</script>
</head>
<body>
		<div id="menu" style="background-color:rgb(200,200,255)">
		<form action="ChemicalTablePrintout.php" align="center">
		</br>
		Search for: 
		<input type="text" name="Search"/>

	               Controlled by:-----------------------------------> the drop down box
		<select name="Controlled">
		<option value="All">List All</option>
		<option value="NEA">NEA</option>
		<option value="SPF">SPF</option>
		<option value="SCDF">SCDF</option>
		</select>
		<input type="submit" value="Search"/>
		</form>
		<!--Centralise the table-->
		<div align="center" >	
		
<?php
		error_reporting (0);
		mysql_select_db("leslie", mysql_connect("localhost","root",""));			              if ($_REQUEST['Controlled']=="All" || $_REQUEST['Controlled']==null)
			{
				$Controlled="";
			}
		else
			{
				$Controlled='AND Controlled = "'.$_REQUEST['Controlled'].'"';
			}
                         $result=mysql_query('select * from table2 WHERE Chemicals LIKE "%'.$_REQUEST['Search'].'%" '.$Controlled);
		$count=0;

_________SelectedChemicalsPrintingPage.php  is the php page my submit button submits to___________

		echo "<form id= myform action=SelectedChemicalsPrintingPage.php method=post>";
				echo " 
					<table border='1'>
					<tr>
					<th>Select</th>   -----> this column is for the checkbox
					<th>Chemicals</th>
					<th>Quantity</th>
					<th>Location</th>
					<th>Controlled</th>
					</tr>
				";		
			while($row = mysql_fetch_array($result))
			{	
			   echo "
				<tr>
				<td><input type=checkbox name=".$count." value=".$row[Chemicals]." /></td>
				<td>" . $row[Chemicals] . "</td>			 
				<td>" . $row[Quantity] . "</td>
				<td>" . $row[Location] . "</td>
				<td>" . $row[Controlled] . "</td>				
				</tr>
			           ";
					$count++;				
				}
			echo'	</table>
				</br>
			              <input type=hidden name=counts value="'.$count.'">
				<input type=submit name=submit >
				</form>
			    ';
?>  	
		<form id="myform">
		Check or Uncheck all: <input type='Button' value='Check/Uncheck' name='checkall' onclick='checkedAll();'>
		</form>
[php]
       $t=time();
       echo(date("D F d Y",$t));
[/php]
</div>
</body>
</html>

Some of these codes were helped by my friend and some were searched online, but i am still kind of bad at it.

the values for the checkboxes are gotten from DB right?

Yep i think you can say that. In the database its actually an imported table from excel in which it consist of
Chemical, Controlled, Location, and quantity but the amount of check box changes accordingly(ie. if you delete 1 chemical, the entire row of that chemical including the information of it <Controlled, Location, and quantity>. will disappear or if you increase, an additional row would appear) This is probably due to the $count++ if i am not wrong.

do u have skype and teamviewer?

it will be easier for me to help you if i see all your code and table structure

haha i can’t all the stuffs are on my lab’s computer and there are also people there doing their work. I don’t want to disturb them. Erm i have skype maybe i"ll go find my lab’s WAMP server and dl it because i heard if i dl a later version of it, some codes will not work.

Oh and how can i contact you?

i will pm you my skype name

Sponsor our Newsletter | Privacy Policy | Terms of Service