• Register
Welcome to Techno Smarter QA, Questions, Answers Community
Welcome to Techno Smarter Q&A, where you can ask questions and receive answers from other members of the community. Ask the tech & programming Question that you want. Guests Posting are allowed.
+3 votes
24 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. 

in PHP by (190 points) 16
reshown by

3 Answers

+1 vote

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 You 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 table From where do you want to copy. 
1. 

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

I have a reference for you. 

COPY ONE MYSQL DATABASE TABLE TO ANOTHER USING PHP

by (6.3k points) 3 20 43
0 votes

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. 

by (4.4k points) 4 14 44
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);
Why are you using insert query two times?
0 votes

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
by (6.3k points) 3 20 43
...