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.

<?php
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')";

mysql_query($add_to_info_query);
$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...)";
mysql_query($add_to_order_query);
$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')";
mysql_query($add_to_acc_query);

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' />";
  
	
mysql_close($con)
?>

Recommended Answers

All 3 Replies

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).

ok...

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

:)

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.