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.

9
  • 4
    Don't. Ever. Use. mysql_*. Commented Jan 30, 2017 at 20:51
  • 1
    Although not directly related to your question I highly recommend sanitizing your inputs. See stackoverflow.com/questions/129677/… Commented Jan 30, 2017 at 20:52
  • 2
    You have $uniqueID var in your foreach but in your $updateSQL you still use $_POST["UniqueID"]. Commented Jan 30, 2017 at 20:55
  • 1
    Now try to get rid of mysql_* Commented Jan 30, 2017 at 20:58
  • 1
    @Jose Manuel Abarca Rodríguez He should, I am waiting for hime to do so. Commented Jan 30, 2017 at 21:18

1 Answer 1

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"));
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.