Hi all,
I am going to attempt to write a script that performs the following:
I have a form with two fields, first field is populated from another table, seconds field is a checkbox.
The form row that hold the fields has a repeat script, so in design view the form has two fields, depending on how many rows of data the form query pulls from the form table, depend on how many rows will appear when the form is viewed in a browser.
Example:
Form query returns 4 rows.
Row 1. description field[row data]. Row 1. checkbox
Row 2. description field[row data]. Row 2. checkbox
Row 3. description field[row data]. Row 3. checkbox
What I want to do is write the content of the description field and the state of the checkbox into another table along with all the other data for that form.
I have not included some parts of the scipt because they are not required by anyone reading this post.
The code so far:
<form name="form1" method="post" action="<?php echo $editFormAction; ?>">
<?php do { ?>
<input name="audititem" type="text" class="audititems" value="<?php echo $row_InspectItems['AuditItem']; ?>" size="80">
<input name="check" type="checkbox" class="checkbox" value="1" checked>
<?php } while ($row_InspectItems = mysql_fetch_assoc($InspectItems)); ?>
<input name="auditby" type="text" class="auditorname" id="auditby" value="<? print $_SESSION['user']['login'];?>" readonly>
<input type="hidden" name="MM_insert" value="form1" />
<input type="hidden" name="clientID" value="<?php echo $_SESSION['user']['member_id']; ?>" />
</form>
$editFormAction = $_SERVER['PHP_SELF'];
if (isset($_SERVER['QUERY_STRING'])) {
$editFormAction .= "?" . htmlentities($_SERVER['QUERY_STRING']);
}
if ((isset($_POST["MM_insert"])) && ($_POST["MM_insert"] == "form1")) {
foreach($_POST["check"] as $check)
{
$insertSQL = sprintf("INSERT INTO RoomAuditResultTest (RecordID, ClientID, ParentID, InspectDate, InspectPrep, InspectAuditedby, InspectRoomNo, AuditItem, AuditCheck, AuditComments) VALUES (%s, %s, %s, %s, %s, %s, %s, %s, %s, %s)",
GetSQLValueString($_POST['RecordID'], "int"),
GetSQLValueString($_POST['ClientID'] = $_SESSION['user']['member_id'], "int"),
GetSQLValueString($_POST['ParentID'] = $_SESSION['user']['parentID'], "int"),
GetSQLValueString($_POST['InspectDate'] = $time, "date"),
GetSQLValueString($_POST['InspectPrep'] = $_POST['prepby'], "text"),
GetSQLValueString($_POST['InspectAuditedby'] = $_POST['auditby'], "text"),
GetSQLValueString($_POST['InspectRoomNo'] = $_POST['room'], "int"),
GetSQLValueString($_POST['AuditItem'] = $_POST['audititem'], "text"),
GetSQLValueString($_POST['AuditCheck'] = $check, "text"),
GetSQLValueString($_POST['AuditComments'] = $_POST['comments'], "text"));
mysql_select_db($database_q, $q);
$Result1 = mysql_query($insertSQL, $q) or die(mysql_error());
}
I think I am on the right track but I am getting an error: Warning: Invalid argument supplied for foreach()
Any advice would be great.