Произошла ошибка при обработке данных. Повторите попытку.
Похоже, эта проблема возникает из-за того, что массивы в запросе POST (счет, дебитор, кредитор, описание и acc_serial) имеют несовпадающее количество. .
Что я пробовал:
Проверка PHP на стороне сервера
Я добавил этап проверки, чтобы убедиться, что все массивы (учетная запись, должник, кредитор, описание и acc_serial) имеют одинаковое количество:
Код: Выделить всё
$account = $_POST["account"];
$debtor = $_POST["debtor"];
$creditor = $_POST["creditor"];
$description = $_POST["description"];
$acc_serial = $_POST["acc_serial"];
if (
count($_POST['account']) !== count($_POST['debtor']) ||
count($_POST['account']) !== count($_POST['creditor']) ||
count($_POST['account']) !== count($_POST['description']) ||
count($_POST['account']) !== count($_POST['acc_serial'])
) {
echo 'toastr.error("Mismatched field count. Please verify the data.");';
exit;
}
Отладка данных POST
I использовал var_dump($_POST) для проверки отправленных данных. Вот результат проблемного запроса:
Код: Выделить всё
array (size=15)
'date' => string '2024-12-09' (length=10)
'entry_num' => string 'JE-0001' (length=7)
'descrip' => string '6565' (length=4)
'company' => string 'sahat' (length=5)
'auth_token' => string '2582f394f3dab3ac3f139d1f7e715d6181ad182a' (length=40)
'serial' => string '3CWZE7B8ZSVIO71Q440HT6HWX1RWKY3B8EL' (length=35)
'j_type' => string 'Manual Entry' (length=15)
'account' =>
array (size=3)
0 => string 'd59f127d86' (length=10)
1 => string 'd5a05ca920' (length=10)
2 => string 'd59fb74cb8' (length=10)
'debtor' =>
array (size=2)
0 => string '2000' (length=4)
1 => string '0' (length=1)
'creditor' =>
array (size=2)
0 => string '0' (length=1)
1 => string '1000' (length=4)
'description' =>
array (size=2)
0 => string 'General Expense' (length=19)
1 => string 'General Expense' (length=19)
'acc_serial' =>
array (size=2)
0 => string 'd59f127d86' (length=10)
1 => string 'd59fb74cb8' (length=10)
Цикл PHP для обработки строк
Код: Выделить всё
foreach ($_POST['account'] as $index => $value) {
if (isset($_POST['account'][$index], $_POST['debtor'][$index], $_POST['creditor'][$index], $_POST['description'][$index], $_POST['acc_serial'][$index])) {
$account = $_POST['account'][$index];
$debtor = $_POST['debtor'][$index];
$creditor = $_POST['creditor'][$index];
$description = $_POST['description'][$index];
$acc_serial = $_POST['acc_serial'][$index];
if (empty($account) || empty($description) || empty($acc_serial) || $debtor === "" || $creditor === "") {
echo 'toastr.error("Please fill all fields in row ' . ($index + 1) . '");';
exit;
}
if (!is_numeric($debtor) || !is_numeric($creditor)) {
echo 'toastr.error("Debtor and Creditor must be numeric in row ' . ($index + 1) . '");';
exit;
}
} else {
echo 'toastr.error("An error occurred while processing data. Please try again.");';
exit;
}
}
Код: Выделить всё
Account
Debit
Credit
Description
[i][/i]
Подробнее здесь: [url]https://stackoverflow.com/questions/79320450/why-is-my-php-script-throwing-a-mismatched-field-count-error-when-adding-dynam[/url]
Мобильная версия