jpweber
Jul 15 2006, 07:24 PM
Hi all. I've researched this to the hilt, and I want to post a fix to the error I've been getting all along, which I've finally put an end to. It's the ol' 1062 Duplicate Entry error, and I have a fix for all. Everybody seems to get these, eventually, but very few people post about 'em in here.
The Problem -- Duplicate Entry 1062 Errors:
I kept having a duplicate error report for sessions. It is a problem with sessions. I was having this error everytime I selected create_account, or wishlist_help.
The Fix:
1) Go to your phpmyadmin, and select the sessions table
2) Select sesskey
3) Click edit
4) It's probably set at the OSC default, which is varchar(32). This is a mistake! Change the type to INT, the length/values should stay at 32.
5) Scroll all the way across to where you see extras and select AUTOINCREMENT from the drop down box.
6) Hit save button
All 1062 Duplicate Enty errors will not be resolved. You won't get 'em again!
If I am correct, OsCommerce creates sessions id for every visit to your website, in case a visitor has cookies disabled. Somehow during configuration, the sessions table probably wasn't configured to autoincrement. This was a simple fix that you wouldn't even need to change any of the values for your test runs. Just fix the sesskey and you're good to go!
J
enigma1
Jul 16 2006, 12:54 AM
the session key is alphanumeric and it should be generated by not following a specific pattern. By changing it to an integer with the autoincrement attribute you allow others to predict easily sessions of customers and even manufacture session cookies. Not a good thing.
sharplab
Jul 21 2006, 03:52 PM
QUOTE (enigma1 @ Jul 16 2006, 12:54 AM)

the session key is alphanumeric and it should be generated by not following a specific pattern. By changing it to an integer with the autoincrement attribute you allow others to predict easily sessions of customers and even manufacture session cookies. Not a good thing.
Had SIMILIAR PROBLEM!
Thanka!
jpweber
Jul 21 2006, 03:58 PM
Okay, I hear what you're trying to say .... but then why did all my problems go away when I switched the sesskey to INT? I researched it, and many people felt the same way. All I know is that all my problems ... duplicate entry 1062 errors, etc., all disappeared.
J
enigma1
Jul 21 2006, 05:23 PM
QUOTE (jpweber @ Jul 21 2006, 10:58 AM)

Okay, I hear what you're trying to say .... but then why did all my problems go away when I switched the sesskey to INT? I researched it, and many people felt the same way. All I know is that all my problems ... duplicate entry 1062 errors, etc., all disappeared.
J
maybe you should check your sessions table with phpmyadmin to see what's going on.
And one other thing. Even if you add an extra auto-increment column to get around it (and that will work) you basically try to hide a problem instead of troubleshooting it. The tep_session_start should generate a unique session via the core php functions. Theoretically and with the default oscommerce there is no issue. So something is going on with your store that causes it.
jpweber
Jul 21 2006, 05:33 PM
Okay, thanks .. I'll look into it and see what I can figure out,
J
jackrabbit
Aug 2 2006, 07:47 PM
QUOTE (jpweber @ Jul 21 2006, 01:33 PM)

Okay, thanks .. I'll look into it and see what I can figure out,
J
Did you find out anything? I am having a similar issue and it's a little frustrating as I'm sure you know.
;-j
jpweber
Aug 2 2006, 07:53 PM
QUOTE (jackrabbit @ Aug 2 2006, 03:47 PM)

Did you find out anything? I am having a similar issue and it's a little frustrating as I'm sure you know.
;-j
You can truncate table sessions when there are no customers online, but really ... the more I've researched, the more I've come up with the fact that you should just go into your phpmyadmin, and change the value of your sesskey in the sessions table to INT, not VarChar. You can always change it back. Just try it; I bet your problems go away.
Go into phpmyadmin and edit the sesskey. Set it to int(32) and set it to auto-increment. Problems solved, and no more problems arise. Worked for me (and several others). Let me know,
J
jackrabbit
Aug 2 2006, 11:30 PM
QUOTE (jpweber @ Aug 2 2006, 03:53 PM)

You can truncate table sessions when there are no customers online, but really ... the more I've researched, the more I've come up with the fact that you should just go into your phpmyadmin, and change the value of your sesskey in the sessions table to INT, not VarChar. You can always change it back. Just try it; I bet your problems go away.
Go into phpmyadmin and edit the sesskey. Set it to int(32) and set it to auto-increment. Problems solved, and no more problems arise. Worked for me (and several others). Let me know,
J
Hey J,
I appreciate your working on a solution to this, but I have to say that Enigma's comment seems quite relevant. Don't you think that, regardless of the results of the fix you propose, you are opening up a potential security risk with it? I have to admit that I don't know enough to be able to say one way or another.
My site is working right now, so I don't feel like I have to put it at risk. My problem is just that when I set products to special I recieve the error once then it goes away until I set another product to special. I would like to know more about troubleshooting this error, but I'm afraid I dont' know where to start.
jpweber
Aug 3 2006, 01:34 AM
No, I don't see the security risk. I mean, there are imaginable scenarios in everything we do. I mean, there's a loophole in things where you can physically type in checkout_success.php into your browser and never even enter your credit card information, and your order goes through. I'm sure there are imaginable loopholes. But I'm leaving my sesskey as INT auto incremented becaused based on my research, it's the right thing to do. And it solved all my problems.
J
boxtel
Aug 3 2006, 12:37 PM
QUOTE (jpweber @ Aug 3 2006, 09:34 AM)

No, I don't see the security risk. I mean, there are imaginable scenarios in everything we do. I mean, there's a loophole in things where you can physically type in checkout_success.php into your browser and never even enter your credit card information, and your order goes through. I'm sure there are imaginable loopholes. But I'm leaving my sesskey as INT auto incremented becaused based on my research, it's the right thing to do. And it solved all my problems.
J
I totally agree with Mark on this.
First of all, I am not sure those sessions will still function but even if they do it is now so much easier to guess an active session id in use by somebody else.
If I go to your store with cookies disabled and get session id 2345 in my url's then chances are pretty high that if I alter that to 2344 I get the information from the previous customer.
With random session id's (alphanumeric or even plain numeric) that is not such a straightforward issue.
And Mark is correct, you are eliminating symptoms not the root cause. if you get duplicate entries then your table is either not cleared, you are generating session id's like wildfire and thus increasing the chances of session id collision or for some other reason you are trying to insert the same session id (instead of updating the existing one).
jpweber
Aug 3 2006, 02:23 PM
Well, I have read SO many articles that say sessions should be INT and auto incremented .... data analysts, programmers, etc. ....
But there's no doubt, even before I added a contribution, I was getting 1062 duplicate error messages. And that's on a clean installation of OSC. I had to constantly truncate the sessions table. So *something* had to be fixed. Through my research, that was my fix. With my customer base, it's highly unlikely that an end-user is going to know how to alter his session -- and even if he does know (which he won't, because I don't even know how to do it), I'm still doubtful he'll get the information from a previous session. As for now, my OSC, 6 contributions later, is functioning well.
J
boxtel
Aug 3 2006, 03:15 PM
QUOTE (jpweber @ Aug 3 2006, 10:23 PM)

Well, I have read SO many articles that say sessions should be INT and auto incremented .... data analysts, programmers, etc. ....
But there's no doubt, even before I added a contribution, I was getting 1062 duplicate error messages. And that's on a clean installation of OSC. I had to constantly truncate the sessions table. So *something* had to be fixed. Through my research, that was my fix. With my customer base, it's highly unlikely that an end-user is going to know how to alter his session -- and even if he does know (which he won't, because I don't even know how to do it), I'm still doubtful he'll get the information from a previous session. As for now, my OSC, 6 contributions later, is functioning well.
J
well, sure, it can very well be that it is an error that comes with the default install.
But if you do it with INT and Autoincrement, at least make sure that the session id is NEVER shown in the url's by forcing cookies. That way they are ALWAYS stored in cookies and not readily visible.
Then again forcing cookies has its own pro's and con's.
Still, that is only a small improvement as people who want to look for other peoples data are bound to know how to read that cookie and still know what likely active id's are.
It is basically like giving all the people in your street a combination lock to their cars and make the combinations sequential. So you know, only if he wants to ofcourse, that your neighbour can have a joy-ride in yours any time.
enigma1
Aug 3 2006, 06:23 PM
what you have there is going to break sooner or later. You changed the session key to integer/auto-increment. Now as the auto-index increases so the chances of passing a key (from the actual session) to the _sess_write function with the first character as a digit (0-9) and that digit will be already in the database which will give you a duplicate entry for the auto-increment field.
jpweber
Aug 3 2006, 06:49 PM
So then what's the fix to the ol' duplicate entry error 1062 in the sessions table? Just keep truncating the table when no customers are online every day?
J
enigma1
Aug 3 2006, 06:57 PM
well this error should not happen in the first place. Check the sessions logic when a new session is to be inserted.
CODE
$check_query = tep_db_query("select count(*) as total from " . TABLE_SESSIONS . " where sesskey = '" . tep_db_input($key) . "'");
$check = tep_db_fetch_array($check_query);
if ($check['total'] > 0) {
return tep_db_query("update " . TABLE_SESSIONS . " set expiry = '" . tep_db_input($expiry) . "', value = '" . tep_db_input($value) . "' where sesskey = '" . tep_db_input($key) . "'");
} else {
return tep_db_query("insert into " . TABLE_SESSIONS . " values ('" . tep_db_input($key) . "', '" . tep_db_input($expiry) . "', '" . tep_db_input($value) . "')");
}
Notice the code performs a check query with the session key passed and inserts this as a new key only when the key is not found in the database.
Now it could be something else like a null key. Have you implement the latest osc upgrade?
http://www.oscommerce.com/solutions/downloadsIt has a specific check filtering the session id with the tep_session_start() function. Make sure you have those changes integrated with your store.
ehong33234
Aug 18 2006, 05:29 PM
QUOTE (enigma1 @ Aug 3 2006, 11:57 AM)

well this error should not happen in the first place. Check the sessions logic when a new session is to be inserted.
CODE
$check_query = tep_db_query("select count(*) as total from " . TABLE_SESSIONS . " where sesskey = '" . tep_db_input($key) . "'");
$check = tep_db_fetch_array($check_query);
if ($check['total'] > 0) {
return tep_db_query("update " . TABLE_SESSIONS . " set expiry = '" . tep_db_input($expiry) . "', value = '" . tep_db_input($value) . "' where sesskey = '" . tep_db_input($key) . "'");
} else {
return tep_db_query("insert into " . TABLE_SESSIONS . " values ('" . tep_db_input($key) . "', '" . tep_db_input($expiry) . "', '" . tep_db_input($value) . "')");
}
Notice the code performs a check query with the session key passed and inserts this as a new key only when the key is not found in the database.
Now it could be something else like a null key. Have you implement the latest osc upgrade?
http://www.oscommerce.com/solutions/downloadsIt has a specific check filtering the session id with the tep_session_start() function. Make sure you have those changes integrated with your store.
I'm sorry I am new to all of this and am getting this error. What is the solution? Thanks in advance...
xiaoge
Aug 19 2006, 09:50 AM
QUOTE (ehong33234 @ Aug 18 2006, 05:29 PM)

I'm sorry I am new to all of this and am getting this error. What is the solution? Thanks in advance...
I have just met that problem.and now i've removed it.
according to
enigma1, osc has made sure that the key item can't be insert twice. but for mysql,there is such a condition that if the string is too long ,it will be cut short to the certain length.
for example: 123456789 exists in the database, if you insert 123456789123,it won't find 123456789123 in the table,but when you insert 123456789123 into the table ,mysql cut it to 123456789 automatically,so,there shows an error.
so,to solve the problem .
first when you have klicked on one category. make sure that in the address there is like:".../index.php?cPath=44&osCsid=0983152dd2ebf0ad25171fbfbdef3c31", and there is nothing after this string. if there is ,the error occurs. and then you should exam you file "./includes/boxes/categories",make sure that the href link is right.
this is my first threat here. sorry for my pool english.
Vger
Aug 19 2006, 12:47 PM
Its' not just the sessions table that you'll get the 1062 error on. Just a few days ago I came across a site that was getting that on the orders table - load one order fine, next order comes up with the 1062 error.
Whilst everything looked fine on the surface, dropping and reinstalling all 'orders' tables fixed the problem. Basically it was the database tables that were the problem.
Vger
enigma1
Aug 19 2006, 02:32 PM
QUOTE (xiaoge @ Aug 19 2006, 04:50 AM)

I have just met that problem.and now i've removed it.
according to enigma1, osc has made sure that the key item can't be insert twice. but for mysql,there is such a condition that if the string is too long ,it will be cut short to the certain length.
for example: 123456789 exists in the database, if you insert 123456789123,it won't find 123456789123 in the table,but when you insert 123456789123 into the table ,mysql cut it to 123456789 automatically,so,there shows an error.
so,to solve the problem .
first when you have klicked on one category. make sure that in the address there is like:".../index.php?cPath=44&osCsid=0983152dd2ebf0ad25171fbfbdef3c31", and there is nothing after this string. if there is ,the error occurs. and then you should exam you file "./includes/boxes/categories",make sure that the href link is right.
this is my first threat here. sorry for my pool english.
This is actually valid. It can happen with the default functions. I have an extra filter to check the key length specifically for this reason. However the default osc sessions.php doesn't. So you do need to check the length in tep_session_start() where it flags the sane id. So the key should be 24<= key <= 32 digits. Or in the _sess_write() handler
jpweber
Aug 22 2006, 04:54 AM
QUOTE (enigma1 @ Aug 19 2006, 10:32 AM)

This is actually valid. It can happen with the default functions. I have an extra filter to check the key length specifically for this reason. However the default osc sessions.php doesn't. So you do need to check the length in tep_session_start() where it flags the sane id. So the key should be 24<= key <= 32 digits. Or in the _sess_write() handler
What does that mean, in Layman's terms, enigma? I mean, I changed my sesskey back to varchar(32), no autoincrement, but I'm still getting at the bottom of the page - primarily when I go to login or create_account and then go to another page:
1062 - Duplicate entry 'd588ac8f1fffe6b3c490188a40eaafce' for key 1
insert into sessions values ('d588ac8f1fffe6b3c490188a40eaafce?osCAdminID=f3cdab335d59c0920155ebdb035fe1c4', '1156214611', 'cart|O:12:\"shoppingcart\":4:{s:8:\"contents\";a:0:{}s:5:\"total\";i:0;s:6:\"weight\";i:0;s:12:\"content_type\";b:0;}language|s:7:\"english\";languages_id|s:1:\"1\";currency|s:3:\"USD\";navigation|O:17:\"navigationhistory\":2:{s:4:\"path\";a:1:{i:0;a:4:{s:4:\"page\";s:18:\"create_account.php\";s:4:\"mode\";s:3:\"SSL\";s:3:\"get\";a:1:{s:6:\"osCsid\";s:76:\"d588ac8f1fffe6b3c490188a40eaafce?osCAdminID=f3cdab335d59c0920155ebdb035fe1c4\";}s:4:\"post\";a:0:{}}}s:8:\"snapshot\";a:0:{}}wishList|O:8:\"wishlist\":0:{}')
[TEP STOP]Can you help me out in regards to what to do?
jpweber
Aug 28 2006, 12:10 AM
I had a person very knowledgable with databases look through mine, and find out that it was the fact that I had autoincrement turned on in that table for the ID which is incorrect. BUG. It only shows if you use different languages. My problems are over, OSC working great.
Shack
Aug 28 2006, 01:30 AM
Mine is back but instead it is at the bottom of the index page and gives an error with the banner mod:
1062 - Duplicate entry '42' for key 1
insert into banners_history (banners_id, banners_shown, banners_history_date) values ('11', 1, now())
[TEP STOP]
Did the fix that some people told you was only a temp fix do the job?
Ron.
Back to reading.
sesam
Sep 14 2006, 03:39 PM
QUOTE
1062 - Duplicate entry '0' for key 1
insert into products_attributes values ('', '348', '4', '22', '', '+')
Is what I get when i try to add from the admin panel a product atribute.
It does not increase it stays somehow on 0.
This must have been happend because off the upgrade to MySQL 5 from 4
jpweber
Sep 14 2006, 03:42 PM
Or you have something in the table mentioned set to autoincrement, thus creating the 1062 error -- the more likely scenario, I'd say. Go into phpmyadmin and check for something that's autoincremented that shouldn't be.
Loon
Sep 28 2006, 09:10 PM
QUOTE (jpweber @ Aug 21 2006, 11:54 PM)

What does that mean, in Layman's terms, enigma? I mean, I changed my sesskey back to varchar(32), no autoincrement, but I'm still getting at the bottom of the page - primarily when I go to login or create_account and then go to another page:
1062 - Duplicate entry 'd588ac8f1fffe6b3c490188a40eaafce' for key 1
insert into sessions values ('d588ac8f1fffe6b3c490188a40eaafce?osCAdminID=f3cdab335d59c0920155ebdb035fe1c4', '1156214611', 'cart|O:12:\"shoppingcart\":4:{s:8:\"contents\";a:0:{}s:5:\"total\";i:0;s:6:\"weight\";i:0;s:12:\"content_type\";b:0;}language|s:7:\"english\";languages_id|s:1:\"1\";currency|s:3:\"USD\";navigation|O:17:\"navigationhistory\":2:{s:4:\"path\";a:1:{i:0;a:4:{s:4:\"page\";s:18:\"create_account.php\";s:4:\"mode\";s:3:\"SSL\";s:3:\"get\";a:1:{s:6:\"osCsid\";s:76:\"d588ac8f1fffe6b3c490188a40eaafce?osCAdminID=f3cdab335d59c0920155ebdb035fe1c4\";}s:4:\"post\";a:0:{}}}s:8:\"snapshot\";a:0:{}}wishList|O:8:\"wishlist\":0:{}')
[TEP STOP]
Can you help me out in regards to what to do?
I just ran into this problem - Duplicate Entry in the sessions table - after downloading my client's /includes/languages/english.php and /includes/languages/english/*.php files. The cart owner edits these files in the osC backend admin tool as they're his information regarding everything - shipping, etc.
Start with the page where you are getting the error (mine was on catalog_index.php) and go BACK to the page where the link is to the problem page. My link was on index.php. Now, hover over the link and check the URL that it's going to send you to. Does it have multiple session IDs in the URL? Appended to each other behind the URL to the page?
I'll put some spaces in but an example:
www . site . com/ catalog_index.php ? osCsid=b4a0b7ae7bfed16e797ddf0a3c56a940 ? osCAdminID=bf6255d450ad1a1e409bfcd189b3aa9d
Notice the TWO session IDs appended to each other (one osCsid and one osCAdminID). And the area between quotes, in red, in your example. I've seen 4 or 5 appended to each other. The only place I have this problem is in the languages files that my cart owner has edited himself. He copies links from his browser, while he's logged into the cart on one browser and into the admin area on another browser. Then he pastes those copied links into a language page (Yup, osCAdminID=xxxxxx.... and all) and saves it. Now it's a permanent part of the file and will always display, AND will always add the current users osCsid in there too so of course it's too long! or a duplicate or whatever.
Take your production languages files and go through them. A good text editor will find the pasted in ids in no time. This doesn't help with the other problems in this thread but I think it may be the answer to your example above.
Graveyard666
Dec 15 2006, 04:35 PM
I am using the contrib "FAST EASY CHECKOUT 3.2" and "HOW DID YOU HEAR ABOUT US? 1.5"
When I hit "continue" on my create_account3.php page, I get this error:
CODE
1062 - Duplicate entry '11' for key 1
insert into customers_info (customers_info_id, customers_info_date_of_last_logon, customers_info_number_of_logons, customers_info_date_account_created, customers_info_date_account_last_modified) values ('11', now(), '1', now(), now() )
[TEP STOP]
but it does successfully writes the customer's info to the db
any ideas why this is happening or how to fix it?
swing
Feb 12 2007, 08:10 AM

Thank you very much Jason Weber. My problem solved perfectly under your guides. Thank you again.
sonictrip.net
Mar 29 2007, 05:04 PM
Hi guys,
I have a similar problem and it must definitely be casued by a contribution so maybe if we all knew what mods were installed on everybody's osc's that are having these problems?
Here's mine:
I have SPPC installed (as well as PDFexport, CVV mod, MaxiDVD multiple images, Who's Online Enhancement, AutoThumbnail, Easy Populate, SEO Assistant, SEO URLs, to name a few) , and they are working properly except for one thing, when i try to copy a product, it gives me a 1062 - Duplicate entry '0-638' for key 1. This has only started happening after SPPC was installed...
When you hit the back button, the new product has been copied correctly and appears in the list.
Now, when you browse the product listing on the main site, the price is displayed correctly, but when you click into a product info page, the price appears as 0.00. However, when you add the product to your cart anyway, the price in the shopping cart appears correctly.
So, its just the product info page which seems to get affected by this problem. Would anyone have any idea why this is happening? Should i change something to INT instead of autoincrement in the DB or is there another way?
Thanks.
Qbito
Apr 17 2007, 06:44 AM
Just for the record, it seems using Paypal_IPN_v2.2 and Unique Order Number contribs will also get you 1062 Duplicate entry error. Customers might choose to use Paypal and leave without completing the order leaving an Order_ID of "0" in Order DB. The next customer that comes along and choses Paypal as their payment method won't be able to complete the order and will get to see the previous customer's name, contacts and shipping information.
Can't find any remedies for this issue yet.
beachkitty85
Jun 22 2007, 02:58 PM
After trying to resolve a Duplicate Entry 1062 Error for several hours, I finally figured out the problem. My client had purchased an SSL certificate and accidently typed in the wrong domain name to purchase it under. There was only one letter difference, but the wrong ssl domain was being recorded in the sessions table and not allowing the creation of accounts. I have disabled ssl forr now until the correct certificate is purchased. I don't think this is the problem for most, but maybe it will help someone.
garlicbred
Jul 31 2007, 08:02 PM
I also get a duplicate entry error - when copying products.
CODE
1062 - Duplicate entry '46-1' for key 1
insert into products_description (products_id, language_id, products_name, products_description, short_desc, products_url, products_viewed) values ('46', '1', 'Electronic Automatic Leveling Rotating Laser', '
The LS521 Laser is a new generation of fully automatic self leveling rotating laser
blah blah ... Used by earthmovers, agriculture, general builders, concretors and all trades where accuracy with rugged reliability over a large working range is what you need.
\r\n
', '
short description2 - includes formatting g dggd gdg dg dg dg g dg deg d g
\r\n
', '', '0')
[TEP STOP]
I have a lot of contribs & hacks ...
I know only a little of sessions & databases, rely on guesswork mostly. So Im guessing it has something to do with the product descriptions. Mostly because Ive done a bit of messing around with short descriptions & the like. .. Although Key 1 probably means "products_id" in which case, yeah It needs to have a different ID... i guess.
Contributions:
FCK
rmh referral (How Did You Hear About Us)
Ultimate SEO URLs v2.1
STS v4.4
"On the Fly" Auto Thumbnailer using GD Library
Anti Robot Validation v2.5
Define Content
info pages
short description
Related Products
featured Products
Active Countries v2.11
Aust Post
.. theres a stack more
Not really a big problem at this stage.. but I want to track this discussion for later when I have more time.
Thanks all, for the really useful info thus far.
markusgnerlich
Aug 11 2007, 03:52 AM
After installing, I received the following error message on every page in the admin section. My error was ...
1062 - Duplicate entry 'c07c86415d6c4ccdc061a352de1fe702' for key 1
insert into sessions values ('c07c86415d6c4ccdc061a352de1fe7022032cd70', '1186804470', 'language|s:7:\"english\";languages_id|s:1:\"1\";selected_box|s:13:\"configuration\";')
I noticed the "duplicate entry" was a truncated version (32 char) of the value in the "insert into sessions values" SQL (40 char). It seems the "sesskey" column in "sessions" should be varchar(40) and not varchar(32). Running the following SQL against my database fixed this problem for me. Make sure you are in the correct database (MySQL catalog) for your osCommerce setup before running.
ALTER TABLE `sessions` MODIFY COLUMN `sesskey` VARCHAR(40) NOT NULL;
In general, the session key should be a unique, but random, identifier, and the total space of random identifiers should be sparsely populated with actively used identifiers at any given time. Auto-incremented integers are a bad idea because they are unique, but not random, and all the active ones are next to each other. It is easy to guess neighboring active session identifiers and impersonate another user.
jsquare
Aug 28 2007, 08:13 PM
Hello, I was also receiving a similar error, which after some thorough research I had found that when the function _sess_write was looking up the $key value (which should only be 32 char long) the $key value actually had the 32 char long key plus ?active= blah blah so, somewhere something was setting the key to be a key + some http variables, at any rate, i just added 2 lines to my _sess_write function:
CODE
function _sess_write($key, $val) {
global $SESS_LIFE;
$expiry = time() + $SESS_LIFE;
$value = $val;
//trim off extra crap on key
$key = substr($key, 0, 32);
$check_query = tep_db_query("select count(*) as total from " . TABLE_SESSIONS . " where sesskey = '" . tep_db_input($key) . "'");
$check = tep_db_fetch_array($check_query);
if ($check['total'] > 0) {
return tep_db_query("update " . TABLE_SESSIONS . " set expiry = '" . tep_db_input($expiry) . "', value = '" . tep_db_input($value) . "' where sesskey = '" . tep_db_input($key) . "'");
} else {
return tep_db_query("insert into " . TABLE_SESSIONS . " values ('" . tep_db_input($key) . "', '" . tep_db_input($expiry) . "', '" . tep_db_input($value) . "')");
}
}
For those of you who dont know where to find that particular function, it is in the includes/functions/sessions.php file.
Hope this helps...
Jon
fizzytsai
Nov 21 2007, 10:00 AM
QUOTE (Graveyard666 @ Dec 15 2006, 04:35 PM)

I am using the contrib "FAST EASY CHECKOUT 3.2" and "HOW DID YOU HEAR ABOUT US? 1.5"
When I hit "continue" on my create_account3.php page, I get this error:
CODE
1062 - Duplicate entry '11' for key 1
insert into customers_info (customers_info_id, customers_info_date_of_last_logon, customers_info_number_of_logons, customers_info_date_account_created, customers_info_date_account_last_modified) values ('11', now(), '1', now(), now() )
[TEP STOP]
but it does successfully writes the customer's info to the db
any ideas why this is happening or how to fix it?
I met this problem when I used SSL.
My solution is changing the PHP code from
tep_redirect(URL);
to
echo '<html><head><meta http-equiv="refresh" content="0;URL=' . URL . '"></head></html>';
exit();
in login.php, create_account.php, and checkout_process.php.
Try it. It may work.
VRADesign
Dec 7 2007, 05:59 PM
QUOTE (markusgnerlich @ Aug 10 2007, 08:52 PM)

After installing, I received the following error message on every page in the admin section. My error was ...
1062 - Duplicate entry 'c07c86415d6c4ccdc061a352de1fe702' for key 1
insert into sessions values ('c07c86415d6c4ccdc061a352de1fe7022032cd70', '1186804470', 'language|s:7:\"english\";languages_id|s:1:\"1\";selected_box|s:13:\"configuration\";')
I noticed the "duplicate entry" was a truncated version (32 char) of the value in the "insert into sessions values" SQL (40 char). It seems the "sesskey" column in "sessions" should be varchar(40) and not varchar(32). Running the following SQL against my database fixed this problem for me. Make sure you are in the correct database (MySQL catalog) for your osCommerce setup before running.
ALTER TABLE `sessions` MODIFY COLUMN `sesskey` VARCHAR(40) NOT NULL;
In general, the session key should be a unique, but random, identifier, and the total space of random identifiers should be sparsely populated with actively used identifiers at any given time. Auto-incremented integers are a bad idea because they are unique, but not random, and all the active ones are next to each other. It is easy to guess neighboring active session identifiers and impersonate another user.
Folks! This is the solution you are looking for. If you change sesskey to INT you will always get a "duplicate entry for key 1" statement.
Just keep sesskey as a VARCHAR and then increase the size above 32 (I made mine 64) and make sure you turn off auto-increment as well.
Simple!
dcphosting
Mar 17 2008, 02:00 PM
QUOTE (jsquare @ Aug 28 2007, 03:13 PM)

//trim off extra crap on key
$key = substr($key, 0, 32);
Thank you.
Your fix solved my duplicate entry error.
Now to solve the cookie vs. session problem that causes this situtation.
Cyberto
Jun 4 2008, 04:47 PM
Hm i got the same problem but either didn't solve the Problem
Cyberto
Jun 4 2008, 05:00 PM
QUOTE (jpweber @ Jul 15 2006, 07:24 PM)

Hi all. I've researched this to the hilt, and I want to post a fix to the error I've been getting all along, which I've finally put an end to. It's the ol' 1062 Duplicate Entry error, and I have a fix for all. Everybody seems to get these, eventually, but very few people post about 'em in here.
The Problem -- Duplicate Entry 1062 Errors:
I kept having a duplicate error report for sessions. It is a problem with sessions. I was having this error everytime I selected create_account, or wishlist_help.
The Fix:
1) Go to your phpmyadmin, and select the sessions table
2) Select sesskey
3) Click edit
4) It's probably set at the OSC default, which is varchar(32). This is a mistake! Change the type to INT, the length/values should stay at 32.
5) Scroll all the way across to where you see extras and select AUTOINCREMENT from the drop down box.
6) Hit save button
All 1062 Duplicate Enty errors will not be resolved. You won't get 'em again!
If I am correct, OsCommerce creates sessions id for every visit to your website, in case a visitor has cookies disabled. Somehow during configuration, the sessions table probably wasn't configured to autoincrement. This was a simple fix that you wouldn't even need to change any of the values for your test runs. Just fix the sesskey and you're good to go!
J
THANKS!!! you're my hero
This is a "lo-fi" version of our main content. To view the full version with more information, formatting and images, please
click here.