×

Please Login or Register to continue.

4
(1.3K Views)

This is table 1 which i want to copy its data and paste into another table. I mean, I want to copy one table data and paste into another table in PHP with MYSQL. 

My first MYSQL database table -

My second MYSQL database table. 

How can I copy one table data into another table via PHP and MYSQL database table. 

(90 Points)
in PHP

Share

3 Answers
(9.4K Points)
2

Copy one table data to another using PHP.

To copy one MySQL table data in another table MYSQL  query is to be used. To copy the data from one table to another table, you have to perform the query of MYSQL  in such a way that your problem is solved. In the query of MYSQL, you have to select the data from a table and have to copy (insert) the other table. To copy the data table of the Msql table, you have to do the following query to MYSQL.

 

INSERT INTO table 2 

SELECT * FROM  table 1  WHERE ...

 

How to MySQL copy query will work. 

Insert into table 2 - Insert the data into table 2 

 

SELECT * FROM  table 1  WHERE ..- Select the data from the table From where do you want to copy. 
1. 

You have to need to use this MYSQL query to perform the copy operation from one table to another.

 

I have a reference for you. 

COPY ONE MYSQL DATABASE TABLE TO ANOTHER USING PHP


Comment

(7.3K Points)
1

Copy one table data into another table is pretty simple using the MYSQL query. First of all, understand the thing because you want to select the data and insert into another MYSQL database table using PHP. It's not a big deal, you can modify query according to your need. 

Use the below query to insert and select data. 

INSERT INTO table2

SELECT * FROM  table1 ; 

The table is another table in which you want to insert the data from table one in PHP. The table1 specifies the table from which you want to select data and paste (insert) data into another table.

You can use Where clause with the select query. 

 INSERT INTO table2

SELECT * FROM  table1 WHERE  ;

 WHERE clause helps to select the specific id-data or other. You can change according to your need. 

 


Comment
This is my code. I used to insert Into another table $result = "INSERT INTO voucher_m(mainhead,subhead,dr,cr) VALUES('$mainhead','$subhead','$dr','$cr'); INSERT INTO voucher_m(voucherno,type) VALUES('$Voucherno','$type') SELECT * FROM next;"; mysqli_multi_query($cser, $result);
osama 23 Sep 2019
Why are you using insert query two times?
vishalrana1 23 Sep 2019

(9.4K Points)
1

If you want to insert data from another table, you have to check and specify the columns too. The MYSQL database table layouts can be different, you should understand this concept and specify the columns (fields ) 

INSERT INTO table2(column1, column1, column1)
SELECT column5, column7, column8 FROM table1 WHERE id = 1

 


Comment

Related Questions :-

Featured Items:-


Certificate and Marksheet system with verification & Franchise in PHP

$75



Certificate system in PHP website | PHP scripts

$22



Home Credito loan finance management multipurpose system in PHP

$65




Your Answer

You can post your answer after login..

Live Chat

Hello! How can we assist you today?