Hello,
I am fairly new with mysql, am trying to perform a sql query.
I have a table with quite a few fields, and my query will extract certain fields and update other tables based on certain criteria.
here is a portion, which gives a 'duplicate key' on a field which is autoincremented id.
[PHP$manf_query = "SELECT DISTINCT manufacturer FROM $table";
//$manf_query = "SELECT * manufacturer FROM $table";
$manf_result = mysql_query($manf_query);
while($manf_data = mysql_fetch_array($manf_result))
{
echo $manf_data['manufacturer'] . '<br>';
$update_manf_query = "INSERT INTO manufacturers VALUES ('', '" . addslashes($manf_data[manufacturer]) . "', '', now(), now())";
echo $update_manf_query;
$update_manf_result = mysql_query($update_manf_query) or die (mysql_error());
$last = mysql_insert_id();
echo $last;
$update_manf_info_query = "INSERT INTO manufacturers_info VALUES ('$last', 1, '', 0, '')";
$update_manf_info_result = mysql_query($update_manf_info_query) or die (mysql_error());
}[/code]
manufacturers table is as follows:
manufacturers_id int(11) PRI NULL not null auto_increment
manufacturers_image varchar(64) NULL
date_added datetime NULL
last_modified datetime NULL
the table i am extracting from is actually coming from an excel spreadsheet which i can successfully populate the table with. (data from the vendor).
any help with this is greatly appreciated.
i did not include the complete script, as if i get this one figured out the rest will follow suit along the same answer.
if you want to see the complete script and tables i can provide.
Thanks in advance.