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

  • SEARCH
  • Home
  • 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 8338603
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T04:38:31+00:00 2026-06-09T04:38:31+00:00

I am trying to update information in a table using MySQLI and PHP. I

  • 0

I am trying to update information in a table using MySQLI and PHP. I know that the data is getting to the update section because I have used print_r() and var_dump() in many spots to verify something is there, but nothing gets changed in the table. Here is what I have for my update:

$conn->query("update inventory set cost = $cost, csmt = $csmt, 
    hold = {$data[$n]['hold']}, commission_level = " . $cLvl .",
    date_process = '$today' where sku = {$data[$n]['sku']}");

If I just add a cost then the table will update, but if I change the csmt or hold fields, nothing gets updated.

If I hardcode the values in the a MySQL query, it works fine. So it appears that there is some problem with the PHP code.

Anyone see where I am going wrong with this?

$today = date('Y-m-d');
$data = json_decode($_POST['data'], true); 

foreach ($data as $value) {
    // check to see if it was taken  off hold
    if ($data[$n]['cost']> 0 || $data[$n]['csmt'] !== 0) {

        //update commission information
        //gather data
        $result = $conn->query("SELECT book_code FROM book_type WHERE book_type_id = {$data[$n]['booktype']}");
        if ($result) { $bookType = $result->fetch_assoc(); }

        $result = $conn->query("SELECT book_type_3 FROM feature WHERE feature_id = {$data[$n]['featureid']}");
        if ($result) { $bookType3 = $result->fetch_assoc(); }

        $result = $conn->query("SELECT condition_id FROM defect WHERE defect_id = {$data[$n]['defect']}");
        if ($result) { $cId = $result->fetch_assoc(); }

        $result = $conn->query("select source_id from inventory where sku = {$data[$n]['sku']}");
        if ($result) { $buyer = $result->fetch_assoc(); }

        $result = $conn->query("SELECT class_code, notes, price, usedbuying_price FROM follette_title WHERE isbn13 = {$data[$n]['isbn']}");
        if ($result) {
            $follett = $result->fetch_assoc();
            $follett_price = $follett['usedbuying_price'];
        }

        if ($data[$n]['cost'] == 0 || $bookType3['book_type_3'] == "DMG")
        {
            $cLvl = null;
        }
        elseif ($bookType['book_code'] == "IE" || $bookType['book_code'] == "AIE")
        {
            $cLvl = 3;
        }
        elseif ($cId['condition_id'] == 1 || $cId['condition_id'] == 2 || $cId['condition_id'] == 3 || $cId['condition_id'] == 4 || $follett['class_code'] == "D" || strpos($follett['notes'],"(T)") == true)
        {
            $cLvl = 2;
        }
        elseif ($cId['condition_id'] == 5)
        {
            $cLvl = 1;
        }

        if ($data[$n]['csmt'] == 0) {
            //get buyer commission rate
            if (!empty($cLvl))
            {
                $result = $conn->query("SELECT lvl" . $cLvl . " FROM buyers WHERE buyer_id = {$buyer['source_id']}");
                //echo"SELECT lvl" . $cLvl . " FROM buyers WHERE buyer_id = {$buyer['source_id']}"; die;
                if ($result) { $comRate = $result->fetch_assoc(); } //print_r($comRate); die;
            }

            //calculate final cost
            if (!empty($comRate['lvl'.$cLvl]))
            {
                $cost = ($data[$n]['cost']) + (($data[$n]['cost']) * $comRate['lvl'.$cLvl]);
            }

        }

        $csmt = $data[$n]['csmt'];
        $conn->query("update inventory set cost = $cost, csmt = $csmt, 
            hold = {$data[$n]['hold']}, commission_level = " . $cLvl .",
            date_process = '$today' where sku = {$data[$n]['sku']}");
  • 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-06-09T04:38:34+00:00Added an answer on June 9, 2026 at 4:38 am

    After much trial and error here is the corrected code that works great.

        $today = date('Y-m-d');
    $data =json_decode($_POST['data'], true); 
    
    foreach($data as $value){
    // check to see if it was taken  off hold
    if($data[$n]['cost']> 1 || $data[$n]['csmt'] == 1)  {
    
        //update commission information
            //gather data
    $result = $conn->query("SELECT book_code FROM book_type WHERE book_type_id = {$data[$n]['booktype']}");
    if($result){$bookType = $result->fetch_assoc();}
    
    $result = $conn->query("SELECT book_type_3 FROM feature WHERE feature_id = {$data[$n]['featureid']}");
    if($result){$bookType3 = $result->fetch_assoc();}
    
    $result = $conn->query("SELECT condition_id FROM defect WHERE defect_id = {$data[$n]['defect']}");
    if($result){$cId = $result->fetch_assoc();}
    
        $result = $conn->query("select source_id from inventory where sku = {$data[$n]['sku']}");
        if($result) {$buyer = $result->fetch_assoc();}
    
    $result = $conn->query("SELECT class_code, notes, price, usedbuying_price FROM follette_title WHERE isbn13 = {$data[$n]['isbn']}");
    if($result){
                $follett = $result->fetch_assoc();
                $follett_price = $follett['usedbuying_price'];
                }
                if($data[$n]['cost'] == 0 || $bookType3['book_type_3'] == "DMG")
        {
            $cLvl = null;
        }
        elseif($bookType['book_code'] == "IE" || $bookType['book_code'] == "AIE")
        {
            $cLvl = 3;
        }
        elseif($cId['condition_id'] == 1 || $cId['condition_id'] == 2 || $cId['condition_id'] == 3 || $cId['condition_id'] == 4 || $follett['class_code'] == "D" || strpos($follett['notes'],"(T)") == true)
        {
            $cLvl = 2;
        }
        elseif($cId['condition_id'] == 5)
        {
            $cLvl = 1;
        }
    
        if($data[$n]['csmt'] == 0){
        //get buyer commission rate
        if(!empty($cLvl))
        {
            $result = $conn->query("SELECT lvl" . $cLvl . " FROM buyers WHERE buyer_id = {$buyer['source_id']}");//
                        //echo"SELECT lvl" . $cLvl . " FROM buyers WHERE buyer_id = {$buyer['source_id']}"; die;
            if($result) {$comRate = $result->fetch_assoc();}//print_r($comRate); die;
        }
    
        //calculate final cost
        if(!empty($comRate['lvl'.$cLvl]))
        {
            $cost = ($data[$n]['cost']) + (($data[$n]['cost']) * $comRate['lvl'.$cLvl]);
        }
    
    }
    // update inventory table
    $conn->query("update inventory set cost = $cost, csmt = {$data[$n]['csmt']}, hold = {$data[$n]['hold']}, commission_level = " . $cLvl .",
             date_process = '$today' where sku = {$data[$n]['sku']}");
    
    
    $holdList[$n] = array('buyer' => $data[$n]['buyer'],
                'process date' => $today,
                    );
    $n++;
    } else {
        $n++; }// end of if statement
    

    }

    I just like to give the final answer in case someone else has the same issue.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to update customers information using a mysql query. The variables have
I'm trying to update a tuple in a table using php and sql via
I'm trying to build a CSS-based table that will be populated with information coming
I am trying update my table from c# ado.net with this function.I am using
I am trying to update cached_name column of callog.calls table in android,but getting sql
I am trying to update a table so that rows that are missing are
Update I'm trying to extract the Tweet Per Hour information from here . However,
Im trying to update a table with the following code. If I change WHERE
Im trying to update the contents of an element after running some php code.
I'm trying to generate a sequence table in MySQL, so that I can get

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.