Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

StackOverflow

StackOverflow Logo StackOverflow Logo

StackOverflow Navigation

Search
Ask A Question

Mobile menu

Close
Ask A Question
  • Home
  • Add group
  • Feed
  • User Profile
  • Communities
  • Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
Home/ Questions/Q 388
Next

StackOverflow Latest Questions

Saralyn
  • 0
  • 0
SaralynBegginer
Asked: January 2, 20252025-01-02T08:34:19+00:00 2025-01-02T08:34:19+00:00In: PHP

html – Why is my PHP script throwing a “Mismatched field count” error when adding dynamic rows in an accounting journal entry?

  • 0
  • 0
html – Why is my PHP script throwing a “Mismatched field count” error when adding dynamic rows in an accounting journal entry?

I am developing an accounting system where users can add journal entries with dynamic rows for account, debtor, creditor, description, and acc_serial. However, when I add a new dynamic row and submit the form, the script throws an error:

An error occurred while processing data. Please try again.

This issue seems to arise because the arrays in the POST request (account, debtor, creditor, description, and acc_serial) have mismatched counts.

What I’ve tried:

PHP server-side validation

I added a validation step to ensure that all arrays (account, debtor, creditor, description, and acc_serial) have the same count:

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 '';
    exit;
}

This triggers the error message when the counts don’t match.

Debugging POST data

I used var_dump($_POST) to inspect the submitted data. Here’s the output for a problematic request:

 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)

Account has 3 items, while debtor, creditor, description, and acc_serial have only 2 items.

PHP loop for processing rows

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 '';
            exit;
        }

        if (!is_numeric($debtor) || !is_numeric($creditor)) {
            echo '';
            exit;
        }
    } else {
        echo '';
        exit;
    }
}

HTML structure for dynamic rows


JavaScript for adding dynamic rows:

$("#add-btn").click(function() {
    let i = $("#dynamicAddRemove tbody tr").length;
    
    $("#dynamicAddRemove").append('' +
        '' +
        '' +
        '' +
        '' +
        '' +
    '');
});

What could cause this mismatch in field counts when adding dynamic rows?

How can I debug or fix this issue to ensure all fields are submitted correctly?

0
  • 0 0 Answers
  • 104 Views
  • 0 Followers
  • 0
Answer
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

Sidebar

Ask A Question
  • Popular
  • Answers
  • W3spoint99

    What is Physics? Definition, History, Importance, Scope (Class 11)

    • 1 Answer
  • W3spoint99

    The Living World – Introduction, Classification, Characteristics, FAQs (Class 11 ...

    • 1 Answer
  • W3spoint99

    Explain - Biological Classification (Class 11 - Biology)

    • 1 Answer
  • Saralyn
    Saralyn added an answer When Humans look at their childhood pictures, the first thing… January 17, 2025 at 3:25 pm
  • Saralyn
    Saralyn added an answer Previously, length was measured using units such as the length… January 17, 2025 at 3:25 pm
  • Saralyn
    Saralyn added an answer Measurement forms the fundamental principle to various other branches of… January 17, 2025 at 3:25 pm

Related Questions

  • Reading fancy apostrophe PHP [duplicate]

    • 0 Answers
  • Unable to send mail via PHPMailer [SMTP->Error: Password not accepted ...

    • 0 Answers
  • Concerns when migrating from PHP 5.6 to 8.4 [closed]

    • 0 Answers
  • Laravel Auth::attempt() error: "Unknown column 'password'" when using a custom ...

    • 0 Answers
  • Core PHP cURL - header origin pass null value

    • 0 Answers

Trending Tags

biology class 11 forces how physics relates to other sciences interdisciplinary science learn mathematics math sets tutorial null sets physics physics and astronomy physics and biology physics and chemistry physics applications science science connections science education sets in mathematics set theory basics types of sets types of sets explained

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help

Footer

  • About US
  • Privacy Policy
  • Questions
  • Recent Questions
  • Web Stories

© 2025 WikiQuora.Com. All Rights Reserved

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.