Forum Moderators: coopster
Here's the code I'm currently using (some additional form data is after it but I figured I would just post the relavant part):
-----------------------------
<?PHP
print "<form action='pm_append_data.php' method='post'>";
$var = $_GET['var'];
$sqlquery1 = "SELECT DISTINCT Task.Desc
FROM Task INNER JOIN (AgrTask INNER JOIN (AgrSched INNER JOIN Equip ON AgrSched.CustNo = Equip.CustNo) ON (AgrTask.AgrmtNo = Equip.SerAgrNo) AND (AgrTask.CustNo = Equip.CustNo)) ON Task.Task = AgrTask.Task
WHERE Equip.ID='$var'";
$result = mysql_query($sqlquery1) or die (mysql_error());
$num=mysql_num_rows($result);
$i=0;
while ($i < $num) {
$a=mysql_result($result,$i,"Desc");
print ($i % 2)? "<tr bgcolor=\"F0F0F0\">" : "<tr bgcolor=\"FFFFFF\">";
print "<td align=left><font Times size=3 px><input name='Items_Completed' type='checkbox' value='$a'>$a</font></td>";
++$i;
}
?>
----------------------------
The "Items Completed" is what I need a running total of or an array submitted into my DB.
The handling form is as follows:
----------------------------
<?
$user=$_POST['#*$!#*$!xxxxx'];
$password=$_POST['xxxxxxxxxxx'];
$EquipID=$_POST['var'];
$PM_Sched=$_POST['PM_Sched'];
$Completed_By=$_POST['Completed_By'];
$Items_Completed=$_POST['Items_Completed'];
$Last_PM_Complete=$_POST['Last_PM_Complete'];
$db="xxxxxxxxx";
$link = mysql_connect("localhost", "xxxxxxxxx", "xxxxxxxxxx");
if (! $link)
die("Couldn't connect to MySQL");
mysql_select_db($db , $link)
or die("Couldn't open $db: ".mysql_error());
mysql_query("INSERT INTO PM_History (EquipID, PM_Sched, Completed_By, Items_Completed, Last_PM_Complete) Values ('$EquipID', '$PM_Sched', '$Completed_By', '$Items_Completed', '$Last_PM_Complete')");
echo "PM Information Added to History!";
mysql_close($link);
?>
--------------------
Any help would be great appreciated!
Thanks again.
PHP and HTML [php.net]
Here's the line that I changed per above:
print "<td align=left><font Times size=3 px><input name='Items_Completed[]' type='checkbox' value='$a'>$a</font></td>";
thanks
In your case if you are trying to insert the collective value of checkboxes into one field, use implode.
$items = implode(",",$Items_Completed);
Then use $items as your variable.
dc