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.