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

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7027207
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T00:13:04+00:00 2026-05-28T00:13:04+00:00

I have a PHP form which posts any number of records for the following:

  • 0

I have a PHP form which posts any number of records for the following:

'asset_ID', 'percent_owner_<?=$members['member_ID']?>'

The PHP page receiving the post separates the percent_owner and member_ID using the following:

foreach ($_POST AS $input => $value) {
    if (stristr($input, 'percent_owner_')) {
    $memberID = str_replace('percent_owner_', '', $input);

    $data[$memberID] = array(
    'memberID' => $memberID,
    'percentOwner' => $value
       );
      }
     }

The next part of the script enters whatever number of records into MySQL using the following:

foreach ($data AS $share) {
    $asset_ID = $_GET['asset_ID'];
    $query = "INSERT INTO shares (asset_ID, member_ID, percent_owner) 
            VALUES ('$asset_ID', '{$share['memberID']}', '{$share['percentOwner']}')";
    $add_shares = $db->exec($query);
    }

All of that works just fine. What I am having trouble with now is before the MySQL insert above, I would like to validate that all the percentages total up to 100%. For example, if there are 3 members with 25%, 25%, and 25%, I want to generate an error message and not do the insert. Right now, you have to manually type in the percentages and total them to 100 yourself. The database will accept less or more than 100% which breaks the math.

I was playing around with the following command before the insert to no avail:

foreach ($data AS $share => $value) {
    $total = array_sum($value);
    }
    include('./view/temp.php');

I am very new to PHP so please bear with my ignorance.

Thanks!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-28T00:13:05+00:00Added an answer on May 28, 2026 at 12:13 am

    Something with the following flow will suffice your need i think.

    foreach ($_POST AS $input => $value) {
        if (stristr($input, 'percent_owner_')) {
        $memberID = str_replace('percent_owner_', '', $input);
    
        $data['memberID'][] = $memberID;
        $data['percentOwner'][] = $value;
          }
         }
    
    if(array_sum($data['percentOwner'] != 100)){
    //generate Error
    }
    
    $c = count($data['memberID']);
    for ($i=0;$i<$c;$i++) {
    
        $asset_ID = $_GET['asset_ID'];
        $query = "INSERT INTO shares (asset_ID, member_ID, percent_owner) 
                VALUES ('$asset_ID', '{$data['memberID'][$i]}', '{$data['percentOwner'][$i]}')";
        $add_shares = $db->exec($query);
        }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a simple HTML form that posts to a PHP page, which will
I have created a PHP form, which, upon submission, goes to another PHP page.
I have a form on which I POST the data with PHP. When the
I have a post html form, and the action is index.php, which is the
In a php-script i have a form, method is post, action-attribute is empty, which
I have created a PHP form which requires the user to select a postcode
I have a php file that contains a form (which contains 2 input boxes
Language: PHP I have a form which asks users for their educational details, course
I have a php form that has a known number of columns (ex. top
I am building a PHP registration form which takes the following fields for up

Explore

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

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

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.