Possible Duplicate:
Unable to insert data into multiple wordpress tables

According to the above diagram I have 2 tables and each table have 1 common column, but the issue is that I have to add the same values in both columns rows. Although wp_terms.term_id has auto increment in database. But I am not understanding how I copy and use wp_terms.term_id value in wp_term_taxonomy.term_id.
I had tried an sql query which i given below:
// create a tag
$query = "INSERT INTO $wpdb->terms (name, slug) VALUES (%s, %s)";
$wpdb->query($wpdb->prepare($query, $name, $slug));
// create the relationship
$query = "INSERT INTO $wpdb->term_taxonomy (term_id, taxonomy) VALUES (%d, %s)";
$wpdb->query($wpdb->prepare($query, LAST_INSERT_ID, 'post_tag'));
But after running this script when I check database through phpmyadmin, i notice that wp_terms table filled correctly but wp_term_taxonomy > term_id column is empty.
And my Actual codes are:
$file_name = $_FILES['tag_import']['name'];
$file_ext = strtolower(end(explode(".", $file_name)));
$file_size = $_FILES['tag_import']['size'];
if (( $file_ext == "xls" ) && ( $file_size < 500000 ))
{
$data = new Spreadsheet_Excel_Reader();
$data->setOutputEncoding('CP1251');
$data->read($_FILES['tag_import']['tmp_name']);
for ($i = 1; $i <= $data->sheets[0]['numRows']; $i++)
{
for ($j = 1; $j <= $data->sheets[0]['numCols']; $j++)
{
// add the new category
$query = "INSERT INTO $wpdb->terms (name, slug) VALUES (%s, %s)";
$wpdb->query($wpdb->prepare($query, $data->sheets[0]['cells'][$i][1], $data->sheets[0]['cells'][$i][2]));
// create the relationship
$query = "INSERT INTO $wpdb->term_taxonomy (term_id, taxonomy) VALUES (%d, %s)";
$wpdb->query($wpdb->prepare($query, LAST_INSERT_ID, 'post_tag'));
}
}
else
{
echo "<div class='error'><p>Invalid file or file size too big.</p></div>";
}
}
Please guide me how can I do that?
I dont do much wordpress but from the documentation it looks like the last id is only filled on
wpdbwhen you use theinsert()method as opposed to usingquery()like you are doing. And its not a global constant its a class variable.