I’m not sure what code to post as this was working and now it’s not but there is a lot of code and I can’t find where it’s breaking. I changed the processing from mysqli to prepared statements but the issue is not related to that. This is being processed from a POST and the values are filtered in various ways as needed for special fields just as they were doing before. However, it’s the fields that contain text and line breaks (and occasional HTML) where the problem is as it seems to want to process each line in the text individually! Below is the error which I understand now that I know what it’s doing but not sure why it’s doing it. The statement should indeed have 5 elements but after it breaks up the text it ends up with giving 45 values!
The code is used for many different tables with different column names so is there a way to make it ignore carriage returns? I checked the text itself to be sure that there were no odd characters but it has just regular line breaks.
mysqli_stmt::execute(): Argument #1 ($params) must consist of exactly 5 elements, 45 present
It’s somewhere in here:
// PREPARE AND FILTER FIELDS FOR PROCESSING
if (isset($_POST)) :
$Values = [];
if ($processType !== "") :
if ($processType === 'insert') unset($_POST['insert']);
if ($processType === 'copy') unset($_POST['copy']);
if ($processType === 'update') unset($_POST['update']);
if ($processType === 'update') unset($_POST['delete']);
// REMOVE ANY UNNEEDED FIELDS SPECIFIED IN $RemoveFields ARRAY
// EXAMPLE $RemoveFields = ['ZipCode', 'Address2'];
if (isset($RemoveFields) && !is_array($RemoveFields)) $RemoveFields = [$RemoveFields];
$filteredarray = (isset($RemoveFields)) ? array_diff_key($_POST, array_flip($RemoveFields)) : $_POST;
array_unique($filteredarray);
// FOR INSERT OR COPY, REMOVE THE ID FIELD
if ($processType === 'insert' || $processType === 'copy') unset($Values['ID']);
// FILTER AND PREPARE VALUES
foreach ($filteredarray as $key=>$value) :
// Do not process security codes
if ($key === 'confirm') continue;
if ($key === 'nonce') continue;
// DO NOT PROCESS LOGIN FORM
if ($key === 'DoLogin') continue;
// DO NOT PROCESS CAPTCHA VERIFYCODE FIELDS
if ($key === 'VerifyCode') continue;
if ($key === 'captcha_challenge') continue;
// DO NOT PROCESS ID FIELD
// if ($key === 'ID') continue;
// PROCESS ANY PASSWORD FIELD
if (Contains("Pass", $key)) :
// ENCODE PASSWORD FIELD
if ($value !== "") $value=md5($value);
// IF NO CHANGES, KEEP ORIGINAL PASSWORD
if ($value === "") continue;
endif;
// PROCESS DATES/TIMES
if (Contains("Date", $key)) :
// PROCESS TO UNIX TIMESTAMP
if (is_numeric($value) && $value < 10000) :
// PROCESS SIX SELECTOR DATE AND TIME FIELDS
if ($DateFieldType === "six2Unix" ) :
$removals = ['year','month','day','hour','minute','second'];
// PROCESS TWO SELECTOR DATE AND TIME FIELDS
elseif ($DateFieldType === "two2Unix" || $DateFieldType === "two2MySQL") :
$removals = ['date','time'];
endif;
$FieldName = trim(str_replace($removals,"",$key));
$value = dateProcess($FieldName,$DateFieldType);
foreach ($removals as $piece) :
if (isset($_POST[$piece.$FieldName])) continue;
endforeach;
$key = $FieldName;
// PROCESS MySQL DATETIME FIELDS TO Unix or MySQL
elseif (!is_numeric($value)) :
if ($DateFieldType === "picker2Unix") : // CALENDAR-TYPE DATE ONLY PICKER TO UNIX
$value = dateProcess($key,$DateFieldType);
elseif ($DateFieldType === "pickertime2MySQL") : // CALENDAR-TYPE DATE PICKER AND TIME SELECTOR TO MYSQL
$value = dateProcess($key,$DateFieldType);
endif;
endif;
endif;
// PROCESS LATITUDE AND LONGITUDE FROM ADDRESS
if ($key === "Address") :
$latlng = locationFromAddress($value);
$latlng = explode(',',$latlng);
endif;
if ($key === "Lat" && isset($latlng[0])) $value = $latlng[0];
if ($key === "Lng" && isset($latlng[1])) $value = $latlng[1];
// PREPARE ARRAY FOR QUERY
$Values[$key] = $value;
endforeach;
$Values = array_unique($Values);
// REMOVE EMPTY VALUES
$Values = array_filter($Values);
$insertVals = join(',',$Values);