Reputation: 621
I received two associative array and I want to update it's values in mysql db. So, I did this:
// for all other contacts
if(isset($_POST['otherAddress']) || isset($_POST['otherComments']))
{
$otherAddress = $_POST['otherAddress'];
$otherComments = $_POST['otherComments'];
foreach (array_keys($otherAddress + $otherComments) as $key)
{
$query = "UPDATE `boardcontacts` SET
`address`='$otherAddress[$key]',`comments`='$otherComments[$key]'
WHERE `memberID` = '$nID' AND `addressType`='other'";
mysql_query($query);
} // for end
} // if end
Problem is: It duplicate all updated rows with the last index of each array. Any help ?
Upvotes: 0
Views: 192
Reputation: 436
Just curious are you updating the value of $nID
??
Because if the foreach
executes without updating $nID
the query will update the values in the same row every time because the where
condition is same every time.
Upvotes: 2