'How to insert data that already have from different table into another table in MYSQL?

How do i get data from different table to insert into another table? I have table (products) which already have (price) values that i have already inserted before. However, I want the (price) and the sold number that I just inserted to multiply and insert into new table (incomes). How to code it?

Here are my code and please correct me if i'm wrong

if(isset($_POST['add-income']))
{
    $pnum = $_POST['pnum']; //data that i just insert in form
    $price = $_POST['price']; // data from different table that already inserted
    $income_amount = $_POST['pnum'] * $_POST['price'];

    $query = "INSERT INTO incomes(sold_numb, income_amount) VALUES ('$pnum', '$income_amount')";
            $query_run = mysqli_query($conn, $query);

            if($query_run)
            {
                $_SESSION['message'] = "Add successfully";
                header('Location: product.php');
                exit(0);

However, when i get the result after submit, the income_amount is 0 in database how do i do it?



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source