Transfer a record from table to table

I am looking to move a record from table to table using mysql/php... I tried the following:

$mysql = "INSERT INTO table2 SELECT * FROM table1 WHERE email = '$email'";
cbonnockAsked:
Who is Participating?
 
maUruConnect With a Mentor Commented:
you probably are getting messed up at the $email because the syntax is fine, try:

$mysql = "INSERT INTO table2 SELECT * FROM table1 WHERE email = '" . mysql_escape_string($email) . "'";
mysql_query($mysql);
0
 
AutogardCommented:
The syntax looks correct.  What kind of errors are you getting?

Do both tables have the exact same structure?
0
 
maUruCommented:
also post your errors, error messages are there for a reason
0
Get your problem seen by more experts

Be seen. Boost your question’s priority for more expert views and faster solutions

 
maUruCommented:
also are table1 and table2 sharing the same schema?
0
 
AutogardCommented:
maUru... you are repeating my posts :)

>>What kind of errors are you getting?
>>also post your errors, error messages are there for a reason

>>Do both tables have the exact same structure?
>>also are table1 and table2 sharing the same schema?
0
 
maUruCommented:
two is better than one.
0
 
AutogardCommented:
haha :)
0
 
TeRReFCommented:
maUru, your first suggestion is a good one about adding mysql_escape_string().
But repeating posts is not good practice. It might lead to wrongfully awarded points by the person that asked the question. Leaving the Expert who came up with the answer first with no points at all. Quite frustrating don't you think? ;)
0
 
maUruCommented:
of course i understand, was a mistake.
0
 
TeRReFCommented:
By the way cbonnock, if you want to move (as stated in your question) the data, it might be easier to just alter the table into the new name?!
ALTER TABLE tbl_name RENAME TO new_tbl_name
0
 
AutogardCommented:
Thanks for the backup TeRReF ;)

All good suggestions... now we just sit back and await the result.... :)
0
 
cbonnockAuthor Commented:
thanks for the speedy, and numerous feedback... the . mysql_escape_string($email) . seems to have fixed the problem. Thanks.
0
All Courses

From novice to tech pro — start learning today.