0

I have a FOREACH loop which is not picking up the first element in the array.

I have a submit form which has the following:

<input name="repaired[<?php echo $row_Faults['UniqueID']; ?>]" type="checkbox" id="repaired" value="1" class="required"/>

If I echo the $_POST['repair'] array I see two records but when the code is run the first record is not been processed.

foreach($_POST['repaired'] as $uniqueID => $repairedValue){   

$updateSQL = sprintf("UPDATE ".$Hist." SET Status=%s, LettoStatus=%s WHERE UniqueID= '".$_POST["UniqueID"]."'",
 GetSQLValueString($_POST['Status'] = $StatusCode , "int"),
GetSQLValueString($_POST['LettoStatus'] = $LettoCode , "int"));

mysql_select_db($database_iMaint, $iMaint);
$Result1 = mysql_query($updateSQL, $iMaint) or die(mysql_error());
}

Can anyone see where I am going wrong.

Many thanks in advance for your time.

DCJones
  • 3,121
  • 5
  • 31
  • 53

1 Answers1

3

You have $uniqueID variable initialized in your foreach but in your $updateSQL you still use $_POST["UniqueID"] So all you need is to change your $updateSQL

$updateSQL = sprintf("UPDATE ".$Hist." SET Status=%s, LettoStatus=%s WHERE
    UniqueID= '".$uniqueID."'",    
    GetSQLValueString($_POST['Status'] = $StatusCode , "int"),
    GetSQLValueString($_POST['LettoStatus'] = $LettoCode , "int"));