Dear Gurus,

I am trying to insert information into three tables then send an email.

The purpose of the code is to place uniform orders within a company with multiple stores. Each store must be able to place orders according to job function as well as order accessories available for the job function. The example below is for the manager job function which has unique uniform requirements specific to an initial hire or promotion. I have another table that has all the accessories for all job function in the store. (because there might be an order where they need aprons for the bakers, hats for supervisors and name tags for all functions)

I also have an orders table that stores the upperlevel of order information such as order id (auto inc), store number, employee name and order date.

I can update all the tables with the following code, however I get an error that says:

Error: Duplicate entry '9' for key 1 (9 is the order id) Assuming it is because I am using the key in two separate queries.

connection info...
$date = date("Y-m-d"); 
$add_to_info_query = "INSERT into orders (store_no, order_date, emp_name) 
VALUES ('$store_no','$date', '$emp_name')";

$last_inserted_mysql_id = mysql_insert_id();
$add_to_order_query = "INSERT into cw_manager (order_id, men_pts, plus all the fields) 
VALUES ($last_inserted_mysql_id, '$men_pts', etc...)";
$add_to_acc_query = "INSERT into cw_acc (order_ID, m_hat, belt, belt_q) 
VALUES ($last_inserted_mysql_id, '$m_hat', '$belt', '$belt_q')";

if (!mysql_query($add_to_order_query,$con))
  die('Error: ' . mysql_error());
$subject = $_REQUEST['store_no']  ;
$message = $_REQUEST['emp_name'] ;
mail( "perley@burgeosands.com", "Store: $subject",
$message, "From: Career Wear Request" );

echo "Your request has been sent.";
echo "<meta HTTP-EQUIV='REFRESH' content='2; url=test_frm_menu.php' />";
7 Years
Discussion Span
Last Post by tieren

hmmm try to I delete the concerned tables, recreated them and make sure the "id" attributes has auto-increment. Also check if you id 9 has no record.


I don't see anything obvious from your code. If I was going to debug this, I would be looking for answers to the following questions:

1. Which insert is failing? We have to presume that it isn't the first one since the order id in the first table should be an auto-increment field.

2. If there was a duplicate order id already on file (in one of the other two tables), where did it come from?

If the answer to the second question isn't obvious, then you may need some debug code at appropriate points in your code to get more info. This module is pretty straightforward and it probably isn't the source of your problem (on its own).



apparently I need a refresh in database design. I had two different types of indexes.

Thanks for pointing me in that direction away from the php


This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.