Forum Moderators: coopster
the error is get is "Invalid query: Duplicate entry '0' for key 2"
this is the code i am using the first part is to get the user id from the table user where the company matches. Then the second part is to add that data to the table.
$result2 = mysql_query("SELECT user_id FROM user WHERE company = '$company' AND auth_level = '1'") or die("Invalid query: " . mysql_error());
while($row=mysql_fetch_array($result2))
{
$user = $row["user_id"];
$result=MYSQL_QUERY("INSERT INTO `invoice` (user_id,totalcost,gst,unitprice,domain,duedate,paid)" . "VALUES('$user','$totalprice','$gst','$unitprice','$domain','$duedate','$paid')") or die("Invalid query: " . mysql_error());
}
[edited by: jatar_k at 4:46 pm (utc) on Dec. 18, 2003]
[edit reason] fixed sidescroll [/edit]
echo the value of $user after the first query and compare it against the proper value in the table to make sure that is working.
Then take a look at the data in the second table, maybe the key is already there. You may have to do an "if not in insert else update" scenario.
I know the error is right so now you need to look at why and where it's coming from.
Another good tip is to echo your constructed sql queries before sending them off to mysql_query.