Jump to content


This topic is now archived and is closed to further replies.


copying and inserting related records into 2nd table? error...

Recommended Posts

hi people

i'm trying to copy all the records that is related to my search.
my first table is 'topics',
and the 2nd table is 'topics_tmp'.

and the codes that producing an error is here below,
//Empty temporary table topics_tmp then fill again with contents from topic_rel[]
for($x=0; $x<=$total_rec; $x++){
//select records from table TOPICS first
$query  = "SELECT * FROM topics WHERE id='$topic_rel[$x]'";
$result = mysql_query($query) or die('Error, query failed');
$row = mysql_fetch_array($result, MYSQL_ASSOC);
$id_tmp = $row['id'];
$title_tmp = $row['title'];
$descrip_tmp = $row['description'];
$url_tmp = $row['url'];

//then insert selected data into TOPICS_TMP temporary table
$query = "INSERT INTO topics_tmp (id, title, description, url) VALUES ('$id_tmp', '$title_tmp', '$descrip_tmp', '$url_tmp')";
mysql_query($query) or die('Error, insert query failed');


when i execute it the error message is showing up -->'Error, insert query failed'.
now what was my mistake here? am i doing the right copying from 1st table
and inserting the records into 2nd table?
Or do i have syntax error here?

Thank you very much in advance... for your kind help.

Share this post

Link to post
Share on other sites
and by the way i am using 'topic_rel[]' an array as my temporary storage of all related topics. am i using it the right way?

thanks again.

Share this post

Link to post
Share on other sites


Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.