If I enter the same code twice I get a PDOException on the second entry. There should be a more graceful error message than this:
PDOException: SQLSTATE[23000]: Integrity constraint violation: 1062 Duplicate entry 'temp8' for key 'code': INSERT INTO {regcode} (created, begins, expires, code, is_active, maxuses) VALUES (:db_insert_placeholder_0, :db_insert_placeholder_1, :db_insert_placeholder_2, :db_insert_placeholder_3, :db_insert_placeholder_4, :db_insert_placeholder_5); Array ( [:db_insert_placeholder_0] => 1394661983 [:db_insert_placeholder_1] => [:db_insert_placeholder_2] => [:db_insert_placeholder_3] => temp8 [:db_insert_placeholder_4] => 1 [:db_insert_placeholder_5] => 1 ) in regcode_save() (line 494 of /....../sites/all/modules/regcode/regcode.module).

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

sh.manishshukla’s picture

Version: 7.x-1.1 » 7.x-1.x-dev

looking into this..

sh.manishshukla’s picture

Status: Active » Needs review
FileSize
2.13 KB

Here is the patch..

bkaestner’s picture

Hey, I looked at your patch and I was getting a warning about getting properties from non-object.

Notice: Trying to get property of non-object in regcode_save()

I remedied the issues by adding this line to the if statement

<?php
if (empty($isExist) || $isExist->rid == FALSE) {

//The rest of your code

}
?>

This checks to see if the result from the query is empty before insert the a new code.

Hope this helps!

sh.manishshukla’s picture

Hi bkaestner,

I have updated the patch as per your suggestion.

Thanks,
Happy Drupaling

steinmb’s picture

Status: Needs review » Postponed (maintainer needs more info)

Not sure I understand the motive here. Could anyone explain

If I enter the same code twice I get a PDOException

?

TR’s picture

Version: 7.x-1.x-dev » 7.x-2.x-dev
Status: Postponed (maintainer needs more info) » Closed (duplicate)