Jump to content

copy record from table1 to table2


quasiman

Recommended Posts

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]
<?php
include('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
Share on other sites

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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.