Copy table data

They have: 47 posts

Joined: Jun 2001

Hi
I am trying to add an archiving feature to a php/MySQL site... Basically, what I need to do is once they have viewed an entry, they can click on archive and it will be copied to a new (archive)table and then deleted from the old one....
I delete part is easy but for some reason the copy part is not working right... Am I doing something wrong?.... I am using the following code:

---------------------------------------

<?php
if ($arc == "ok"){
mysql_query("INSERT INTO listarchive (name,company,phone,extension,email)
SELECT name,company,phone,extension,email FROM list WHERE ID=
$ID");
}
?>

#($ID is provided by the link)
--------------------------------------
If anyone knows of another way of doing this, please let me know.
Thanks for your help,
Mizzy

druagord's picture

He has: 335 posts

Joined: May 2003

i think that when you specify the field you need VALUES like this

<?php
if ($arc == "ok"){
mysql_query("INSERT INTO listarchive (name,company,phone,extension,email) VALUES (
SELECT name,company,phone,extension,email FROM list WHERE ID=
$ID)");
}
?>

or if those are all the fields you have in the table use

<?php
if ($arc == "ok"){
mysql_query("INSERT INTO listarchive
SELECT * FROM list WHERE ID=
$ID");
}
?>

IF , ELSE , WHILE isn't that what life is all about

Want to join the discussion? Create an account or log in if you already have one. Joining is fast, free and painless! We’ll even whisk you back here when you’ve finished.