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 921565
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T18:53:27+00:00 2026-05-15T18:53:27+00:00

I am working with a CMS system, and using a kind of smartform am

  • 0

I am working with a CMS system, and using a kind of smartform am inserting fields into a table.

In these fields are the name of a product, quantity and cost.

cost and product name are taken from a products table, while quantity is input manually.

I understand this is not the best architecture, but I am limited with the system I am working with.

What I want to do, is change the value of cost after it is inserted, to quantity * cost.

What is the easiest way to do this?

  • 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-15T18:53:27+00:00Added an answer on May 15, 2026 at 6:53 pm

    If you have your hands tied so tightly that you are unable to change the table structure, then you probably won’t be able to use a trigger, but here goes anyway.

    This is a sample table structure:

    DROP TABLE IF EXISTS `products`;
    
    CREATE TABLE `products` (
        `id` INT(11) NOT NULL AUTO_INCREMENT,
        `product` VARCHAR(255),
        `quantity` INT(11) NOT NULL,
        `cost` DECIMAL(6,2) NOT NULL,
        PRIMARY KEY  (`id`)
    ) ENGINE=InnoDB;
    

    Create a trigger which updates the cost prior to it being inserted into the products table:

    DELIMITER //
    DROP TRIGGER IF EXISTS update_cost//
    CREATE TRIGGER update_cost BEFORE INSERT ON products
    FOR EACH ROW BEGIN
        SET NEW.cost = NEW.cost * NEW.quantity;
    END;
    //
    DELIMITER ;
    

    Insert a couple of products into the table:

    INSERT INTO `products` (`product`, `quantity`, `cost`) VALUES
    ('Acme portable hole', 10, 20),
    ('Acme jet pack', 1000, 2);
    

    The cost is updated automatically:

    SELECT * FROM prodcuts;
    
    +----+--------------------+----------+---------+
    | id | product            | quantity | cost    |
    +----+--------------------+----------+---------+
    |  1 | Acme portable hole |       10 |  200.00 |
    |  2 | Acme jet pack      |     1000 | 2000.00 |
    +----+--------------------+----------+---------+
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am working in the confines of a CMS system, which defines certain fields
I am working on CMS system using smarty. The one cms system could support
I am working on a CMS system tries to support multilingual natively. I have
I am working on a CMS using CakePHP and I want to create a
I'm working on a CMS using VB.NET 3.5 and I'm stuck on a concept.
I am working with a CMS like system, phpBMS, which defines a certain way
I am working within the confines of a php based CMS like system, which
I am working on a CMS project using ASP.Net 3.5/Visual studio 2008.This is the
I am working on a CMS system for my business, and need to be
I'm working with a CMS (ExpressionEngine) that wraps paragraph tags around images. I'm using

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.