1062 - Duplicate entry '1' for key 'PRIMARY'

Everything has been working perfectly for years, then decided to upgrade PHP.
Prior PHP v. 5.2.28
Upgraded to PHP v. 5.5 - site completely broken
Downgraded to PHP v. 5.3.29 (unable to downgrade all the way back to 5.2.28)

The error we are getting now is:
1062 - Duplicate entry '1' for key 'PRIMARY'

INSERT INTO products (products_id, products_quantity, products_model, products_image, products_price, products_date_added, products_last_modified, products_date_available, products_weight, products_status, products_tax_class_id, manufacturers_id) VALUES ('1', 100000, 'fonts: 
line 1: Abbey.ttf
font color: Silver
decal type: Windshield Lettering
decal option: 3 inch x 33 inch
', '', '10.95', '2015-03-27 7:52:42', '2015-03-27 7:52:42', '', '0.8', '0', '1', '0')

[TEP STOP]

Open in new window


Table information is
`products_id` INT( 10 ) NOT NULL AUTO_INCREMENT ;

Open in new window


Last incremental id was 92690. Now it is trying to use id of 1. If I delete id 1, then I get the following error:

Untitled.jpg
Here I believe the code causing the issue:
 // custom designed decal
      case 'add_custom' : if ($HTTP_POST_VARS['msg']) {
	  if($HTTP_POST_VARS['customEdit']=='Edit'){
	  
	  $id = tep_edit_custom_in_cart($HTTP_POST_VARS['productID'], $HTTP_POST_VARS['msg'], $HTTP_POST_VARS['msg1'],$HTTP_POST_VARS['msg2'],$HTTP_POST_VARS['msg3'],$HTTP_POST_VARS['msg4'],$HTTP_POST_VARS['msg5'], $HTTP_POST_VARS['font1'], $HTTP_POST_VARS['font2'], $HTTP_POST_VARS['font3'], $HTTP_POST_VARS['font4'], $HTTP_POST_VARS['font5'], $HTTP_POST_VARS['rgbmix'], $HTTP_POST_VARS['effect'], $HTTP_POST_VARS['shadow_direction'], $HTTP_POST_VARS['rgb_sh'], $HTTP_POST_VARS['rgb_ol'], $HTTP_POST_VARS['decal_type'], $HTTP_POST_VARS['type_option'], $HTTP_POST_VARS['width'], $HTTP_POST_VARS['height']);
  tep_redirect(tep_href_link($goto, tep_get_all_get_params($parameters), 'NONSSL'));
  
	  }else{
   $id = tep_add_custom_to_cart($HTTP_POST_VARS['msg'], $HTTP_POST_VARS['msg1'],$HTTP_POST_VARS['msg2'],$HTTP_POST_VARS['msg3'],$HTTP_POST_VARS['msg4'],$HTTP_POST_VARS['msg5'], $HTTP_POST_VARS['font1'], $HTTP_POST_VARS['font2'], $HTTP_POST_VARS['font3'], $HTTP_POST_VARS['font4'], $HTTP_POST_VARS['font5'], $HTTP_POST_VARS['rgbmix'], $HTTP_POST_VARS['effect'], $HTTP_POST_VARS['shadow_direction'], $HTTP_POST_VARS['rgb_sh'], $HTTP_POST_VARS['rgb_ol'], $HTTP_POST_VARS['decal_type'], $HTTP_POST_VARS['type_option'], $HTTP_POST_VARS['width'], $HTTP_POST_VARS['height']);
   $cart->add_cart($id, $HTTP_POST_VARS['id']+$quantity, $HTTP_POST_VARS['id']); // add to cart
  tep_redirect(tep_href_link($goto, tep_get_all_get_params($parameters), 'NONSSL'));
  }}
                              break;
      // performed by the 'buy now' button in product listings and review page
      case 'buy_now' :        if (isset($HTTP_GET_VARS['products_id'])) {
                               if (tep_has_product_attributes($HTTP_GET_VARS['products_id'])) {
                                 tep_redirect(tep_href_link(FILENAME_PRODUCT_INFO, 'products_id=' . $HTTP_GET_VARS['products_id']));
                               } else {
                                 $cart->add_cart($HTTP_GET_VARS['products_id'], $cart->get_quantity($HTTP_GET_VARS['products_id'])+1);
                               }
                             }

Open in new window

v0rtex79Asked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Dave BaldwinFixer of ProblemsCommented:
For the `products_id` VALUE in the INSERT use NULL or 0.  That will cause the auto-increment value to be used.  

$HTTP_POST_VARS should be changed to $_POST before you move to a newer version of PHP.  $HTTP_POST_VARS is deprecated and is expected to be removed in the future.
http://php.net/manual/en/reserved.variables.post.php
0
jimyXCommented:
If "products_id" is an auto-increment field under "products" Table, why do you assign value for it when inserting?
`products_id` INT( 10 ) NOT NULL AUTO_INCREMENT ;

Shouldn't the Insert Query be like this:
INSERT INTO products (
products_quantity, products_model, products_image, products_price, products_date_added, products_last_modified, 
products_date_available, products_weight, products_status, products_tax_class_id, manufacturers_id) VALUES (
100000, 'fonts: 
line 1: Abbey.ttf
font color: Silver
decal type: Windshield Lettering
decal option: 3 inch x 33 inch', 
'', '10.95', '2015-03-27 7:52:42', '2015-03-27 7:52:42', '', '0.8', '0', '1', '0');

Open in new window

or like this:
INSERT INTO products (
products_id, products_quantity, products_model, products_image, products_price, products_date_added, products_last_modified, 
products_date_available, products_weight, products_status, products_tax_class_id, manufacturers_id) VALUES (
NULL,100000, 'fonts: 
line 1: Abbey.ttf
font color: Silver
decal type: Windshield Lettering
decal option: 3 inch x 33 inch', 
'', '10.95', '2015-03-27 7:52:42', '2015-03-27 7:52:42', '', '0.8', '0', '1', '0');

Open in new window


In order to get the Auto-Increment value added, rather than passing value that might conflict with existing previously added value?

Adding Auto-Increment values manually is overdo the task of making value generator. Also it introduces gaps into your values, if jumped to big numbers.
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
v0rtex79Author Commented:
Can you tell me from the code I posted where I would need to make changes? I'm not a coder so I need some hand holding. :)
0
Cloud Class® Course: Ruby Fundamentals

This course will introduce you to Ruby, as well as teach you about classes, methods, variables, data structures, loops, enumerable methods, and finishing touches.

Dave BaldwinFixer of ProblemsCommented:
While I think @jimyX gave you code for the insert, you will likely need to hire a coder to update all of your code to the newer standards.  I believe this will go way beyond hand-holding.
0
jimyXCommented:
1062 - Duplicate entry '1' for key 'PRIMARY'

INSERT INTO products (products_id, products_quantity, products_model, products_image, products_price, products_date_added, products_last_modified, products_date_available, products_weight, products_status, products_tax_class_id, manufacturers_id) VALUES (/*'1'*/ NULL, 100000, 'fonts:
line 1: Abbey.ttf
font color: Silver
decal type: Windshield Lettering
decal option: 3 inch x 33 inch
', '', '10.95', '2015-03-27 7:52:42', '2015-03-27 7:52:42', '', '0.8', '0', '1', '0')

[TEP STOP]

Edit:
I agree with Dave.
You might have a lot of such so-many-to-come issues.
0
v0rtex79Author Commented:
Can I hire one of you?
0
Dave BaldwinFixer of ProblemsCommented:
Sorry, not me.  I already have plenty of clients.
0
Ray PaseurCommented:
I'm a little concerned about this -- if the script is inserting a constant value into the AUTO_INCREMENT id field, it would have been failing years ago.  It may be that your test data set has changed or there are other changes that are not apparent to us here.  In any case, you're on the right track to hire a professional to help you remediate and upgrade.  There are a lot of things that can go wrong and some of them have dire consequences, so don't take any chances with important data.  Back up everything now.

Many of the E-E experts have a "hire me" button on their profiles.

You might want to seriously consider starting over with net-new code.  PHP has come a long way since this was written, and whoever wrote this did not do you any "favors."  At first glance, it looks like something that is untestable.  Like an old car that breaks down -- it may make more sense to get a new car than try to find all the parts and keep repairing things as they break.  Today it would not cost very much to use an ORM framework like Laravel to rebuild the back-end.  A Laravel expert would be expected to have a high hourly rate and very high hourly output.

Going forward, PHP has a change log that you can refer to when you get ready to do upgrades.  All of the compatibility issues are well-documented.  It's a lot to read, but it's require reading for anyone who depends on PHP.
http://php.net/ChangeLog-5.php

Best of luck with your project, ~Ray
0
gr8gonzoConsultantCommented:
That code looks a lot like osCommerce. If it is, are you working with a customization / add-on for it and what version of it are you on?
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
PHP

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.