quasiman Posted July 25, 2006 Share Posted July 25, 2006 I'm trying to copy all records in table1 to table2 (then verify and delete from table1, but I haven't gotten that far yet).But table2 has additional columns, so I must specify each of the columns I want copied. Even doing so I'm getting the error "Column count doesn't match value count at row 1".Here's what I'm trying:[code=php:0]<?phpinclude('includes/config.inc');// Make the DB connection$sql_link = mysql_connect ("$sql_host", "$sql_user", "$sql_pass") or exit;mysql_select_db("$sql_db");//collect info$result = mysql_query("SELECT 'id', 'time', 'name', 'address', 'subject_text', 'body_text' FROM table1");//insert the info into the 2nd table$move = "INSERT INTO mailbox (id, time, name, address, subject_text, body_text) VALUES ('$result')";mysql_query($move) or die(mysql_error());?>[/code]Any help would be greatly appreciated! Link to comment https://forums.phpfreaks.com/topic/15556-copy-record-from-table1-to-table2/ Share on other sites More sharing options...
fenway Posted July 25, 2006 Share Posted July 25, 2006 Sounds like you want:[code]INSERT INTO mailbox (id, time, name, address, subject_text, body_text) SELECT 'id', 'time', 'name', 'address', 'subject_text', 'body_text' FROM table1 [/code] Link to comment https://forums.phpfreaks.com/topic/15556-copy-record-from-table1-to-table2/#findComment-63233 Share on other sites More sharing options...
quasiman Posted July 25, 2006 Author Share Posted July 25, 2006 do you mean:[code=php:0]$move_message = "INSERT INTO mailbox (id, time, name, address, subject_text, body_text) SELECT 'id', 'time', 'name', 'address', 'subject_text', 'body_text' FROM table1";mysql_query($move_message) or die(mysql_error());[/code]All this does is insert "id, time, name, address, subject_text, body_text" - not the actual records Link to comment https://forums.phpfreaks.com/topic/15556-copy-record-from-table1-to-table2/#findComment-63244 Share on other sites More sharing options...
king arthur Posted July 25, 2006 Share Posted July 25, 2006 Try it without the single quotes. INSERT....SELECT syntax is explained here: [url=http://www.phpfreaks.com/mysqlmanual/page/manual_SQL_Syntax.html#INSERT_SELECT]http://www.phpfreaks.com/mysqlmanual/page/manual_SQL_Syntax.html#INSERT_SELECT[/url] Link to comment https://forums.phpfreaks.com/topic/15556-copy-record-from-table1-to-table2/#findComment-63297 Share on other sites More sharing options...
fenway Posted July 25, 2006 Share Posted July 25, 2006 Right, no string literals... I just blindly copied & pasted.. my bad. Link to comment https://forums.phpfreaks.com/topic/15556-copy-record-from-table1-to-table2/#findComment-63438 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.