i use a mysql wrapper class to gather datas from form. i need to update a mysql text field called “accommodation” with a string from a loop like that:
foreach($_POST['postcode'] as $index => $cp)
{
$cp = $cp;
$name = $_POST['name'][$index];
$insert = "$cp,$name;";
}
$data['accommodation'] = $insert;
$db->update("circuits_".$_POST['year']."", $data, "type='".$tour."'");
if i echo $insert inside the loop everything is fine, i have my complete string. but i need to update the database outside the loop to have the all string. and yet i gather only the last value of the array, not the all string. thanks for your help.
You are always overwriting the $insert;
Try doing this:
this way you’ll add to the variable, not replace it.
Remember to add $insert = “” before the loop.