Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Transfer a record from table to table

Posted on 2006-07-17
12
Medium Priority
?
214 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 5
  • 4
  • 2
  • +1
12 Comments
 
LVL 8

Expert Comment

by:Autogard
ID: 17124787
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 2000 total points
ID: 17124999
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
ID: 17125002
also post your errors, error messages are there for a reason
0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
LVL 7

Expert Comment

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

Expert Comment

by:Autogard
ID: 17125142
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
ID: 17125245
two is better than one.
0
 
LVL 8

Expert Comment

by:Autogard
ID: 17125262
haha :)
0
 
LVL 29

Expert Comment

by:TeRReF
ID: 17126167
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
ID: 17126174
of course i understand, was a mistake.
0
 
LVL 29

Expert Comment

by:TeRReF
ID: 17126185
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
ID: 17126228
Thanks for the backup TeRReF ;)

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

Author Comment

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

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Foreword (July, 2015) Since I first wrote this article, years ago, a great many more people have begun using the internet.  They are coming online from every part of the globe, learning, reading, shopping and spending money at an ever-increasing ra…
Many old projects have bad code, but the budget doesn't exist to rewrite the codebase. You can update this code to be safer by introducing contemporary input validation, sanitation, and safer database queries.
The viewer will learn how to dynamically set the form action using jQuery.
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.
Suggested Courses

610 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