Jump to content

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


bilis_money

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,
[code]
//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');

}
[/code]

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.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

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.