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 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 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've been working on a custom CMS in PHP and haven't run into any
I've been working on a case using Pyrocms, a CI-based CMS, on my local
I'm working with a CMS, Joomla, and there's a core class which renders a
Got myself in a bit of a pickle here ... working on a CMS
I'm working on a module for a CMS. This module is distributed as a
I'm working on a custom CMS for my own use and was thinking about
I'm working on a PHP CMS like project and I'm trying to find out

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.