Solved

Transfer a record from table to table

Posted on 2006-07-17
12
206 Views
Last Modified: 2008-03-10
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'";
0
Comment
Question by:cbonnock
  • 5
  • 4
  • 2
  • +1
12 Comments
 
LVL 8

Expert Comment

by:Autogard
Comment Utility
The syntax looks correct.  What kind of errors are you getting?

Do both tables have the exact same structure?
0
 
LVL 7

Accepted Solution

by:
maUru earned 500 total points
Comment Utility
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
 
LVL 7

Expert Comment

by:maUru
Comment Utility
also post your errors, error messages are there for a reason
0
 
LVL 7

Expert Comment

by:maUru
Comment Utility
also are table1 and table2 sharing the same schema?
0
 
LVL 8

Expert Comment

by:Autogard
Comment Utility
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
 
LVL 7

Expert Comment

by:maUru
Comment Utility
two is better than one.
0
Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

 
LVL 8

Expert Comment

by:Autogard
Comment Utility
haha :)
0
 
LVL 29

Expert Comment

by:TeRReF
Comment Utility
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
 
LVL 7

Expert Comment

by:maUru
Comment Utility
of course i understand, was a mistake.
0
 
LVL 29

Expert Comment

by:TeRReF
Comment Utility
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
 
LVL 8

Expert Comment

by:Autogard
Comment Utility
Thanks for the backup TeRReF ;)

All good suggestions... now we just sit back and await the result.... :)
0
 

Author Comment

by:cbonnock
Comment Utility
thanks for the speedy, and numerous feedback... the . mysql_escape_string($email) . seems to have fixed the problem. Thanks.
0

Featured Post

What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

Join & Write a Comment

Author Note: Since this E-E article was originally written, years ago, formal testing has come into common use in the world of PHP.  PHPUnit (http://en.wikipedia.org/wiki/PHPUnit) and similar technologies have enjoyed wide adoption, making it possib…
Part of the Global Positioning System A geocode (https://developers.google.com/maps/documentation/geocoding/) is the major subset of a GPS coordinate (http://en.wikipedia.org/wiki/Global_Positioning_System), the other parts being the altitude and t…
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
The viewer will learn how to count occurrences of each item in an array.

763 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now