Forums / Bug Reports / [Done v155] PHP Fatal error: 1062uplicate entry '0' for key 'PRIMARY'

[Done v155] PHP Fatal error: 1062uplicate entry '0' for key 'PRIMARY'

Locked

Views: 6,278

Results 1 to 20 of 35
This thread is locked. New replies are disabled.
28 Feb 2016, 10:04 AM
#1
mydakota avatar

mydakota

New Zenner

Join Date:
Feb 2016
Posts:
58
Plugin Contributions:
0

[Done v155] PHP Fatal error: 1062uplicate entry '0' for key 'PRIMARY'

not sure if to post this here please direct me to right place if not im new please help me , every time i try to add more the one attribute i get the time out please refresh page to try again in the error logs i get this UTC] PHP Fatal error: 1062uplicate entry '0' for key 'PRIMARY' :: if i do a check msql table after trying to add attribute in zencart I see this in phpmyadmin database .products_attributes check warning Found row where the auto_increment column has the ......
its weird because if i restore with the same backup files and sql to my test server wamp it works fine. but restoring to my web host crazydomains i get these auto_increment issues and cant add more than one attribute ive spent days trying to fix it and have become stuck. please please help me. ill attach log file below.

[27-Feb-2016 06:49:37 UTC] PHP Fatal error: 1062uplicate entry '0' for key 'PRIMARY' :: insert into products_attributes (products_attributes_id, products_id, options_id, options_values_id, options_values_price, price_prefix, products_options_sort_order, product_attribute_is_free, products_attributes_weight, products_attributes_weight_prefix, attributes_display_only, attributes_default, attributes_discounted, attributes_image, attributes_price_base_included, attributes_price_onetime, attributes_price_factor, attributes_price_factor_offset, attributes_price_factor_onetime, attributes_price_factor_onetime_offset, attributes_qty_prices, attributes_qty_prices_onetime, attributes_price_words, attributes_price_words_free, attributes_price_letters, attributes_price_letters_free, attributes_required)
values (0,
'311',
'2',
'5',
'0',
'+',
'2',
'1',
'0',
'+',
'0',
'0',
'1',
'',
'1',
'0',
'0',
'0',
'0',
'0',
'',
'',
'0',
'0',
'0',
'0',
'0') in /home/anarchy2/public_html/includes/classes/db/mysql/query_factory.php on line 120

28 Feb 2016, 10:04 AM
#2
mydakota avatar

mydakota

New Zenner

Join Date:
Feb 2016
Posts:
58
Plugin Contributions:
0

Re: [Done v155] PHP Fatal error: 1062uplicate entry '0' for key 'PRIMARY'

plase help me ;(

28 Feb 2016, 6:31 PM
#3
mesnitu avatar

mesnitu

Totally Zenned

Join Date:
Aug 2014
Location:
Lisbon
Posts:
597
Plugin Contributions:
0

Re: [Done v155] PHP Fatal error: 1062uplicate entry '0' for key 'PRIMARY'

mydakota:

its weird because if i restore with the same backup files and sql to my test server wamp it works fine. but restoring to my web host crazydomains i get these auto_increment issues and cant add more than one attribute

Can give much help, but has you've have guess it, there's a ID that's already there.
If you say in your wamp you can restore a backup and it works ok, something is wrong with that table.
Don't even know why a products_attributes_id would be "0" , if fact It should be auto incremented. But I'm not a expert.

I would try to export to csv that table from wamp and your domain and compared then. There's has to be something duplicated.

And after you restore in wamp, you can insert new stuff ?

“Though the problems of the world are increasingly complex, the solutions remain embarrassingly simple.” ― Bill Mollison

28 Feb 2016, 6:47 PM
#4
lat9 avatar

lat9

Administrator

Join Date:
Sep 2009
Location:
Stuart, FL
Posts:
14,109
Plugin Contributions:
56

Re: [Done v155] PHP Fatal error: 1062uplicate entry '0' for key 'PRIMARY'

You could try installing the myDEBUG Backtrace plugin (https://www.zen-cart.com/downloads.php?do=file&id=1879%29; that will let you (and us) know who is making the malformed call to insert that attribute record.

When/if you do post the generated log, be aware that your admin's secret folder name will appear as part of the data. You'll want to xxx that information out so that the world doesn't know your admin folder's name.

29 Feb 2016, 5:53 AM
#5
mc12345678 avatar

mc12345678

Totally Zenned

Join Date:
Jul 2012
Posts:
16,908
Plugin Contributions:
2

Re: [Done v155] PHP Fatal error: 1062uplicate entry '0' for key 'PRIMARY'

If understand the discussion, action, and results correctly, the socalled malformed query is in admin/attributes_controller.php beginning at line 311:

 $db->Execute("insert into " . TABLE_PRODUCTS_ATTRIBUTES . " (products_attributes_id, products_id, options_id, options_values_id, options_values_price, price_prefix, products_options_sort_order, product_attribute_is_free, products_attributes_weight, products_attributes_weight_prefix, attributes_display_only, attributes_default, attributes_discounted, attributes_image, attributes_price_base_included, attributes_price_onetime, attributes_price_factor, attributes_price_factor_offset, attributes_price_factor_onetime, attributes_price_factor_onetime_offset, attributes_qty_prices, attributes_qty_prices_onetime, attributes_price_words, attributes_price_words_free, attributes_price_letters, attributes_price_letters_free, attributes_required)
                          values (0,
                                  '" . (int)$products_id . "',
                                  '" . (int)$options_id . "',
                                  '" . (int)$values_id . "',
                                  '" . (float)zen_db_input($value_price) . "',
                                  '" . zen_db_input($price_prefix) . "',
                                  '" . (int)zen_db_input($products_options_sort_order) . "',
                                  '" . (int)zen_db_input($product_attribute_is_free) . "',
                                  '" . (float)zen_db_input($products_attributes_weight) . "',
                                  '" . zen_db_input($products_attributes_weight_prefix) . "',
                                  '" . (int)zen_db_input($attributes_display_only) . "',
                                  '" . (int)zen_db_input($attributes_default) . "',
                                  '" . (int)zen_db_input($attributes_discounted) . "',
                                  '" . zen_db_input($attributes_image_name) . "',
                                  '" . (int)zen_db_input($attributes_price_base_included) . "',
                                  '" . (float)zen_db_input($attributes_price_onetime) . "',
                                  '" . (float)zen_db_input($attributes_price_factor) . "',
                                  '" . (float)zen_db_input($attributes_price_factor_offset) . "',
                                  '" . (float)zen_db_input($attributes_price_factor_onetime) . "',
                                  '" . (float)zen_db_input($attributes_price_factor_onetime_offset) . "',
                                  '" . zen_db_input($attributes_qty_prices) . "',
                                  '" . zen_db_input($attributes_qty_prices_onetime) . "',
                                  '" . (float)zen_db_input($attributes_price_words) . "',
                                  '" . (int)zen_db_input($attributes_price_words_free) . "',
                                  '" . (float)zen_db_input($attributes_price_letters) . "',
                                  '" . (int)zen_db_input(

As previously pointed out the auto-increment ought to assign a new value other than 0 to the attribute_id, but there are some servers that are not setup to do that with a value of zero presented... Two solutions I see, either find all such assignments in all queries and either attempt to use null instead or remove such an assignment or work with your host to have them adjust or help you to adjust the mysql settings so that auto_numbering can't start on 0 but instead 1.

ZC Installation/Maintenance Support <- Site
Contribution for contributions welcome...

29 Feb 2016, 5:41 PM
#6
mydakota avatar

mydakota

New Zenner

Join Date:
Feb 2016
Posts:
58
Plugin Contributions:
0

Re: [Done v155] PHP Fatal error: 1062uplicate entry '0' for key 'PRIMARY'

thank you mate this would seem to best answer kinda the track i was going down but haven't had much luck in working it out i even tried rolling site back to a few weeks ago and same issue my backups don't go back that far as i cleaned them out wops> but i don't think a restore will fix it as like you say some hosting servers don't like 0 and wont auto-increment and yet my test server running wamp with updated phpmyadmin will auto-increment fine no problems is defiantly a hosting sql issue with auto-increment 0 . seems strange as the crazy-domains hosting support zencart and have auto installer on there site surely they must know this is a issue. ill keep digging and try have a play with the database see what i can do wish me luck and thanks for the reply's i don't want to lose my site :(

29 Feb 2016, 6:06 PM
#7
mydakota avatar

mydakota

New Zenner

Join Date:
Feb 2016
Posts:
58
Plugin Contributions:
0

Re: [Done v155] PHP Fatal error: 1062uplicate entry '0' for key 'PRIMARY'

also should i be using this check box when importing my database in phpmyadmin <Do not use AUTO_INCREMENT for zero values> has this caused the issue i was told it should be check also using this option on my test server everything works fine so i guess its fine just seem to sound very much like the issue lol

1 Mar 2016, 3:49 AM
#9
mydakota avatar

mydakota

New Zenner

Join Date:
Feb 2016
Posts:
58
Plugin Contributions:
0

Re: [Done v155] PHP Fatal error: 1062uplicate entry '0' for key 'PRIMARY'

ok so in this dose not say anything about CHECKED: Add AUTO_INCREMENT value as in the older versions of phpmyadmin but say Settings not mentioned can be left to their defaults. and this option Add AUTO_INCREMENT value is by default checked so i assume its correct. but to me i sounds suspect to the error i get

Using phpMyAdmin v3.4 or higher:
The ideal settings to do a backup via phpMyAdmin are shown below. Settings not mentioned can be left to their defaults.
You will be presented with a choice of "Quick Backup" or "Custom", CHOOSE "Custom", and then make the following selections:

  • Output: - Save output to a file, leave all the other settings under Output as defaults, except maybe Compression:
    OPTIONAL: - Compression: "gzipped" (or whatever you prefer... gzip makes smaller files, but zip files are easier to read on Windows computers)
  • Format: - SQL
  • Format-specific options: - You ONLY need to check the "structure and data" option.
  • Object creation options: - check ALL the boxes in this section, except the "Add CREATE DATABASE / USE statement" option.
  • Data dump options: - choose "INSERT" from the pulldown, and check the "both of the above" option. The rest of the defaults are fine.
1 Mar 2016, 4:53 AM
#10
kobra avatar

kobra

Black Belt

Join Date:
Aug 2005
Location:
Arizona
Posts:
31,500
Plugin Contributions:
4

Re: [Done v155] PHP Fatal error: 1062uplicate entry '0' for key 'PRIMARY'

  • CHECKED: Add AUTO_INCREMENT value
    This is listed in v3.3 or lower

Zen-Venom Get Bitten

1 Mar 2016, 5:39 AM
#11
mydakota avatar

mydakota

New Zenner

Join Date:
Feb 2016
Posts:
58
Plugin Contributions:
0

Re: [Done v155] PHP Fatal error: 1062uplicate entry '0' for key 'PRIMARY'

ok i have copying pasting this into sql section of admin panel didn't help me still issue is still there i would have though this would have fixed it.

This script simply rebuilds the auto-increment settings on tables which should have them.

$ Id: $

ALTER TABLE upgrade_exceptions CHANGE COLUMN upgrade_exception_id upgrade_exception_id smallint(5) NOT NULL auto_increment;
ALTER TABLE address_book CHANGE COLUMN address_book_id address_book_id int(11) NOT NULL auto_increment;
ALTER TABLE address_format CHANGE COLUMN address_format_id address_format_id int(11) NOT NULL auto_increment;
ALTER TABLE admin CHANGE COLUMN admin_id admin_id int(11) NOT NULL auto_increment;
ALTER TABLE admin_activity_log CHANGE COLUMN log_id log_id int(15) NOT NULL auto_increment;
ALTER TABLE authorizenet CHANGE COLUMN id id int(11) unsigned NOT NULL auto_increment;
ALTER TABLE banners CHANGE COLUMN banners_id banners_id int(11) NOT NULL auto_increment;
ALTER TABLE banners_history CHANGE COLUMN banners_history_id banners_history_id int(11) NOT NULL auto_increment;
ALTER TABLE categories CHANGE COLUMN categories_id categories_id int(11) NOT NULL auto_increment;
ALTER TABLE configuration CHANGE COLUMN configuration_id configuration_id int(11) NOT NULL auto_increment;
ALTER TABLE configuration_group CHANGE COLUMN configuration_group_id configuration_group_id int(11) NOT NULL auto_increment;
ALTER TABLE countries CHANGE COLUMN countries_id countries_id int(11) NOT NULL auto_increment;
ALTER TABLE coupon_email_track CHANGE COLUMN unique_id unique_id int(11) NOT NULL auto_increment;
ALTER TABLE coupon_gv_queue CHANGE COLUMN unique_id unique_id int(5) NOT NULL auto_increment;
ALTER TABLE coupon_redeem_track CHANGE COLUMN unique_id unique_id int(11) NOT NULL auto_increment;
ALTER TABLE coupon_restrict CHANGE COLUMN restrict_id restrict_id int(11) NOT NULL auto_increment;
ALTER TABLE coupons CHANGE COLUMN coupon_id coupon_id int(11) NOT NULL auto_increment;
ALTER TABLE currencies CHANGE COLUMN currencies_id currencies_id int(11) NOT NULL auto_increment;
ALTER TABLE customers CHANGE COLUMN customers_id customers_id int(11) NOT NULL auto_increment;
ALTER TABLE customers_basket CHANGE COLUMN customers_basket_id customers_basket_id int(11) NOT NULL auto_increment;
ALTER TABLE customers_basket_attributes CHANGE COLUMN customers_basket_attributes_id customers_basket_attributes_id int(11) NOT NULL auto_increment;
ALTER TABLE email_archive CHANGE COLUMN archive_id archive_id int(11) NOT NULL auto_increment;
ALTER TABLE featured CHANGE COLUMN featured_id featured_id int(11) NOT NULL auto_increment;
ALTER TABLE files_uploaded CHANGE COLUMN files_uploaded_id files_uploaded_id int(11) NOT NULL auto_increment;
ALTER TABLE geo_zones CHANGE COLUMN geo_zone_id geo_zone_id int(11) NOT NULL auto_increment;
ALTER TABLE group_pricing CHANGE COLUMN group_id group_id int(11) NOT NULL auto_increment;
ALTER TABLE ezpages CHANGE COLUMN pages_id pages_id int(11) NOT NULL auto_increment;
ALTER TABLE languages CHANGE COLUMN languages_id languages_id int(11) NOT NULL auto_increment;
ALTER TABLE layout_boxes CHANGE COLUMN layout_id layout_id int(11) NOT NULL auto_increment;
ALTER TABLE manufacturers CHANGE COLUMN manufacturers_id manufacturers_id int(11) NOT NULL auto_increment;
ALTER TABLE media_clips CHANGE COLUMN clip_id clip_id int(11) NOT NULL auto_increment;
ALTER TABLE media_manager CHANGE COLUMN media_id media_id int(11) NOT NULL auto_increment;
ALTER TABLE media_types CHANGE COLUMN type_id type_id int(11) NOT NULL auto_increment;
ALTER TABLE music_genre CHANGE COLUMN music_genre_id music_genre_id int(11) NOT NULL auto_increment;
ALTER TABLE newsletters CHANGE COLUMN newsletters_id newsletters_id int(11) NOT NULL auto_increment;
ALTER TABLE orders CHANGE COLUMN orders_id orders_id int(11) NOT NULL auto_increment;
ALTER TABLE orders_products CHANGE COLUMN orders_products_id orders_products_id int(11) NOT NULL auto_increment;
ALTER TABLE orders_products_attributes CHANGE COLUMN orders_products_attributes_id orders_products_attributes_id int(11) NOT NULL auto_increment;
ALTER TABLE orders_products_download CHANGE COLUMN orders_products_download_id orders_products_download_id int(11) NOT NULL auto_increment;
ALTER TABLE orders_status_history CHANGE COLUMN orders_status_history_id orders_status_history_id int(11) NOT NULL auto_increment;
ALTER TABLE orders_total CHANGE COLUMN orders_total_id orders_total_id int(10) unsigned NOT NULL auto_increment;
ALTER TABLE paypal_session CHANGE COLUMN unique_id unique_id int(11) NOT NULL auto_increment;
ALTER TABLE paypal CHANGE COLUMN paypal_ipn_id paypal_ipn_id int(11) unsigned NOT NULL auto_increment;
ALTER TABLE paypal_testing CHANGE COLUMN paypal_ipn_id paypal_ipn_id int(11) unsigned NOT NULL auto_increment;
ALTER TABLE paypal_payment_status CHANGE COLUMN payment_status_id payment_status_id int(11) NOT NULL auto_increment;
ALTER TABLE paypal_payment_status_history CHANGE COLUMN payment_status_history_id payment_status_history_id int(11) NOT NULL auto_increment;
ALTER TABLE product_type_layout CHANGE COLUMN configuration_id configuration_id int(11) NOT NULL auto_increment;
ALTER TABLE product_types CHANGE COLUMN type_id type_id int(11) NOT NULL auto_increment;
ALTER TABLE products CHANGE COLUMN products_id products_id int(11) NOT NULL auto_increment;
ALTER TABLE products_attributes CHANGE COLUMN products_attributes_id products_attributes_id int(11) NOT NULL auto_increment;
ALTER TABLE products_description CHANGE COLUMN products_id products_id int(11) NOT NULL auto_increment;
ALTER TABLE products_options_values_to_products_options CHANGE COLUMN products_options_values_to_products_options_id products_options_values_to_products_options_id int(11) NOT NULL auto_increment;
ALTER TABLE project_version CHANGE COLUMN project_version_id project_version_id tinyint(3) NOT NULL auto_increment;
ALTER TABLE project_version_history CHANGE COLUMN project_version_id project_version_id tinyint(3) NOT NULL auto_increment;
ALTER TABLE query_builder CHANGE COLUMN query_id query_id int(11) NOT NULL auto_increment;
ALTER TABLE record_artists CHANGE COLUMN artists_id artists_id int(11) NOT NULL auto_increment;
ALTER TABLE record_company CHANGE COLUMN record_company_id record_company_id int(11) NOT NULL auto_increment;
ALTER TABLE reviews CHANGE COLUMN reviews_id reviews_id int(11) NOT NULL auto_increment;
ALTER TABLE salemaker_sales CHANGE COLUMN sale_id sale_id int(11) NOT NULL auto_increment;
ALTER TABLE specials CHANGE COLUMN specials_id specials_id int(11) NOT NULL auto_increment;
ALTER TABLE tax_class CHANGE COLUMN tax_class_id tax_class_id int(11) NOT NULL auto_increment;
ALTER TABLE tax_rates CHANGE COLUMN tax_rates_id tax_rates_id int(11) NOT NULL auto_increment;
ALTER TABLE template_select CHANGE COLUMN template_id template_id int(11) NOT NULL auto_increment;
ALTER TABLE zones CHANGE COLUMN zone_id zone_id int(11) NOT NULL auto_increment;
ALTER TABLE zones_to_geo_zones CHANGE COLUMN association_id association_id int(11) NOT NULL auto_increment;

2 Mar 2016, 3:49 AM
#12
mydakota avatar

mydakota

New Zenner

Join Date:
Feb 2016
Posts:
58
Plugin Contributions:
0

Re: [Done v155] PHP Fatal error: 1062uplicate entry '0' for key 'PRIMARY'

Looks like I either need to start from scratch a new site or change hosting company's as it would seem to be a I issue with the CrazyDomains server weird though as all worked ok until I had to restore site all my back ups were done correctly as per instructions on ZenCart site for php 5.5 eprox version . So if I rebuild my site and have to restore it I'll just have to keep rebuilding it over and over how much fun . Would seem the CrazyDomains team have no idea what this error is

2 Mar 2016, 4:26 AM
#14
webmanstudios avatar

webmanstudios

New Zenner

Join Date:
Dec 2013
Location:
Adelaide, South Australia
Posts:
29
Plugin Contributions:
0

Re: [Done v155] PHP Fatal error: 1062uplicate entry '0' for key 'PRIMARY'

Hi mydakota,

I had/have the same issue on a Crazy Domains on a shared server.

I feel it's definitely a CD issue, although they insist is a ZC issue and to talk to the developer about fixing the issue. It happened to my site a little while back, after they updated their servers.

i haven't been able to find a fix for the issue here in the forums or online and my attributes for products currently doesn't work. I have implemented a Neanderthal technology solution, basically advising customers to enter their attribute options in the comments section of the special instructions form of the checkout forms - most do, but now and again a customer forgets or overlooks entering the details and a simple phone call is in order to determine the customer attribute options.

So the bottom line, until I get time to rebuild the site from scratch my Neanderthal solution will have to do.

Good luck sorting out your issue. :)

kind Regards

les :)

2 Mar 2016, 5:54 AM
#15
mydakota avatar

mydakota

New Zenner

Join Date:
Feb 2016
Posts:
58
Plugin Contributions:
0

Re: [Done v155] PHP Fatal error: 1062uplicate entry '0' for key 'PRIMARY'

hi thanks for this info yes its defiantly there servers i was hesitant on using crazy-domains as my host. ill will give them the opportunity to fix the issue before i dedicate my life to warning others with videos and spam bots lol I did find a way to get attributes to work and apply by going into phpmyadmin and under product attributes i find the attribute with a 0 as its id and manually call it something like 22 or similar to the other attributes but not the same then i can add more but have to keep manually change its attribute id in phpmyadmin maybe a easier way for you to at least update your attributes. I will prob be forced down this path but if i have to rebuild my site i will move hosting company's to one that actually can run zen-cart properly. but before i jump the gun ill give them some time to fix this and keep you updated on a possible fix if i find one.

2 Mar 2016, 6:01 AM
#16
kobra avatar

kobra

Black Belt

Join Date:
Aug 2005
Location:
Arizona
Posts:
31,500
Plugin Contributions:
4

Re: [Done v155] PHP Fatal error: 1062uplicate entry '0' for key 'PRIMARY'

mydakota,
I was looking back through the information you supplied and did not see php ver or mysql ver

Using ZC v1.5.4 I believe requires the mysqli extentions

You can go to your admin > tools > server/version info and see if msqli is present

BTW: This is not a "bug" so someone might relocate this posting

Zen-Venom Get Bitten

2 Mar 2016, 7:54 AM
#17
mydakota avatar

mydakota

New Zenner

Join Date:
Feb 2016
Posts:
58
Plugin Contributions:
0

Re: [Done v155] PHP Fatal error: 1062uplicate entry '0' for key 'PRIMARY'

Attachment 16080

we are still to determine weather this is a zencart or server issue so could easily be a bug

2 Mar 2016, 8:47 AM
#18
design75 avatar

design75

Totally Zenned

Join Date:
Dec 2009
Location:
Amersfoort, The Netherlands
Posts:
2,862
Plugin Contributions:
5

Re: [Done v155] PHP Fatal error: 1062uplicate entry '0' for key 'PRIMARY'

mydakota:

we are still to determine weather this is a zencart or server issue so could easily be a bug

What I think Cobra meant, was that it is not a bug in a default Zen Cart setup, but it may stil be a "bug" in your configuration, but then it should not be in the bugs section of the forum.
Have you tried running your site on a localhost like xampp? if it runs ok there, we could probably rule out an error in the site.

2 Mar 2016, 9:36 AM
#19
mydakota avatar

mydakota

New Zenner

Join Date:
Feb 2016
Posts:
58
Plugin Contributions:
0

Re: [Done v155] PHP Fatal error: 1062uplicate entry '0' for key 'PRIMARY'

works fine on my wamp server no issues at all

2 Mar 2016, 11:32 AM
#20
mc12345678 avatar

mc12345678

Totally Zenned

Join Date:
Jul 2012
Posts:
16,908
Plugin Contributions:
2

Re: [Done v155] PHP Fatal error: 1062uplicate entry '0' for key 'PRIMARY'

Have searched a little more on this issue. The problem described typically comes from the mysql server having the mode: NO_AUTO_VALUE_ON_ZERO set. Review of the settings appears possible through direction offered on the following mysql page: http://dev.mysql.com/doc/refman/5.7/en/sql-mode.html#sqlmode_no_auto_value_on_zero

Specifically through a query such as:

SELECT @@GLOBAL.sql_mode;
SELECT @@SESSION.sql_mode;

Would have to work with the hosting company about disabling the above mode either globally or for you.

ZC Installation/Maintenance Support <- Site
Contribution for contributions welcome...