EDIT* Sorry I didn't mean to add that error message in the topic title.
Hey guys, I'm new to PHP and MYSQL and I have been searching for hours for a way to copy the data from a row in one table (all columns) and insert it into another table (same column names). I've also browsed around Daniweb and haven't found a direct solution for my code. I'm sorry if this has already been posted here.
Here is some of my code
I connect to the first database, get the row and break down the columns into variables. I then close that connection and open another connection on another server and attempt to add those variables to the second database
$con1 = /*connect to server 1*/ $con2 = /*connect to server 2*/ mysql_select_db("database1", $con1) or die(mysql_error()); $result = mysql_query("SELECT * FROM table1 ORDER BY id DESC", $con1); $row1 = mysql_fetch_array($result); $row2 = mysql_fetch_array($result); $row3 = mysql_fetch_array($result); /*etc...*/ /*after finding the row, break it up*/ $one = $row3['col1']; $two = $row3['col2']; $three = $row3['col3']; /*etc...*/ mysql_close($con1); mysql_select_db("databse2", $con2) or die(mysql_error()); mysql_query (" INSERT INTO table2 (col1, col2, col3, col4, col5) VALUES('$one','$two','$three','$four','$five') ", $con2) or die(mysql_error());
I have an echo setup after the first connection, the second connection, and at the very end that echos all of the variables. They all work and I get no errors, but when I check the second database there is no data. I have tried countless ways of doing this, however, I always run into a problem or error. This is the closest I have gotten to completing the task at hand.
If anyone has some tips or advise, I would greatly appreciate the help. I've read hundreds of forums posts and gone through several options in the manual. maybe I missed something?
Edited by PsychicTide: n/a