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! Quote Link to comment 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] Quote Link to comment 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 Quote Link to comment 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] Quote Link to comment 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. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.