find and extract data from one table and insert it into another in php and mysql
Get the solution ↓↓↓I am creating a sales system and I want to know the cost of a product through its code / id. The part of uploading all the data of a product is fine, but I want to know the cost and that cost to introduce it to another table.
THIS IS IN THE PRODUCT TABLE:
CODE NAME COST PRICE
44730 doritos 1 2
447390 ice 4 6
As an example I want to know what is the cost of the product with the code 44730, for that I have to use the following :
$db = mysqli_connect("localhost", "root", "", "db_midatabase");
$cost = mysqli_query($db, "
SELECT cost FROM product WHERE code=44730
");
Now that same data that in theory should be 1 I want to introduce it in another table that should do this:
$sql = "
INSERT INTO myothertable (cost) VALUES ('$cost')";
mysqli_query($db, $sql);
and there is my mistake and it is that simply if you add something to the database but the data is 0, someone who helps me solve this problem please I would appreciate it
Answer
Solution:
You could use a single INSERT/SELECT query
INSERT INTO myothertable (cost)
SELECT cost FROM product
WHERE code=44730
Share solution ↓
Additional Information:
Link To Answer People are also looking for solutions of the problem: gd library extension not available with this php installation.
Didn't find the answer?
Our community is visited by hundreds of web development professionals every day. Ask your question and get a quick answer for free.
Similar questions
Find the answer in similar questions on our website.
Write quick answer
Do you know the answer to this question? Write a quick response to it. With your help, we will make our community stronger.