0

please can someone help i have been working on this query for hours. i am trying to copy certain columns from my table ptb_registrations and insert them as a new row into ptb_users.

my ptb_registrations table looks like this:

id | username | password | firstname | lastname | email 1 dave password james tanner [email protected] 2 jonx10 gundam00 eric davies [email protected] 3 33csgge henry10 daniel gilmart [email protected] 

from these columns i only want to insert id, firstname, lastname, email and password NOT username.

So my ptb_user table looks like this:

 id | user_id | password | firstname | lastname | email 1 1 password james tanner [email protected] 2 2 gundam00 eric davies [email protected] 3 3 henry10 daniel gilmart [email protected] 

id is an auto increment value, and i want user_id to have the same value as the auto_incremented id column when the data is inserted too (if this is possible so where id is 1 - user_id will be 1 also)

so far i have tried loads of different ways to get the columns inserted from ptb_registrations and into ptb_users but nothing is working for me.

cans someone please show me where i am going wrong, thank you.

 // Make a safe query $query ="insert into ptb_users(id, first_name) select ptb_registrations.id, ptb_registrations.firstname from ptb_registrations, temp where ptb_users.id=temp.id; "; mysql_query($query)or die('Could not update members: ' . mysql_error()); 
1

1 Answer 1

0

There's no way to guarantee that your new AUTO_INCREMENT will match your previous user ID's... What happens if there is a break in the sequence? Your best bet is to re-assign the new table's id after you've inserted the records.

Your query should something like this:

INSERT INTO ptb_user (user_id, password, firstname, lastname, email) SELECT id, password, firstname, lastname, email FROM ptb_registrations ORDER BY id 

P.S. I hope you're not saving the passwords in plain-text.

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.