drasl Posted August 26, 2016 Share Posted August 26, 2016 (edited) Hi guys, Randomly in my code a query won't execute. The only thing I think about this is that a query didn't finish when the next query start. When an user create an account, I send them a mail with hookcreateAccount with a hash so they can confirm their emails. When they click on the link, this function will execute: public function execActivation() { $link=Tools::getValue('link'); if ($this->isMD5($link)) Db::getInstance()->Execute('UPDATE '._DB_PREFIX_.'mail_verification SET is_confirmed=1 WHERE hash="'.$link.'"'); $sql = 'SELECT * FROM '._DB_PREFIX_.'mail_verification WHERE hash="'.$link.'"'; if ($row = Db::getInstance()->getRow($sql)) $id= $row['id_customer']; Db::getInstance()->Execute('UPDATE '._DB_PREFIX_.'cart_rule set active = 1 WHERE id_customer = '.$id.' AND code LIKE "PET%"'); Tools::redirect('my-account.php'); } - First I update the mail_verification table and set that the account has been confirmed. - Next, I select from the same table the id of the customer where the hash is same that the link (I think here is the problem, maybe the first query didn't finish to it won't take the customer id. - To end I update the specific cart rule to active = 1 for this customer. This module is designed for if the client want a coupon he/she has to confirm his/her email. The first query ALWAYS will be executed, but randomly and rarely the next querys won't do it, then the client has the email confirmed but the coupon won't be activated. I hope you can enlighten me before thinking of creating a trigger... Edited August 26, 2016 by lsard (see edit history) Link to comment Share on other sites More sharing options...
musicmaster Posted August 27, 2016 Share Posted August 27, 2016 How do you know that sometimes the second query is not executed? Could it not be that it is executed but doesn't return a valid customer id or that something goes wrong with that "code" field? You should add some debugging code to catch such situations. Link to comment Share on other sites More sharing options...
drasl Posted August 27, 2016 Author Share Posted August 27, 2016 Because there are customers with the mail confirmed but they haven't de coupon active. These clients who has this issue are normal clients. Link to comment Share on other sites More sharing options...
musicmaster Posted August 27, 2016 Share Posted August 27, 2016 Because there are customers with the mail confirmed but they haven't de coupon active. These clients who has this issue are normal clients. Computers tend to be logical. If they execute the first line they will also execute the next, unless they have a good reason not to. The way you write it sounds like you consider your computer irrational. If you really believe that you might consider looking for another profession because you are making life impossible for yourself. There are many things that could go wrong here. Some interference of an anti-virus/antispam program, certain codes that get damaged in the process of encoding and decoding, your hash not being properly escaped in the query, etc. One other thing that you could try is taking such a code that didn't work and run it through the code yourself. Link to comment Share on other sites More sharing options...
drasl Posted August 29, 2016 Author Share Posted August 29, 2016 (edited) Computers tend to be logical. If they execute the first line they will also execute the next, unless they have a good reason not to. The way you write it sounds like you consider your computer irrational. If you really believe that you might consider looking for another profession because you are making life impossible for yourself. There are many things that could go wrong here. Some interference of an anti-virus/antispam program, certain codes that get damaged in the process of encoding and decoding, your hash not being properly escaped in the query, etc. One other thing that you could try is taking such a code that didn't work and run it through the code yourself. Thanks musicmaster. Of course I know computers tends to be logical, if you think that the things I write sounds like I consider computer are irrational you're wrong and you really misunderstood me, maybe because I'm Spanish and I can't communicate in the best way. There is no problem about antispam, the clients who confirms the mail ALWAYS will be updated to "is_confirmed = 1". The problem is not the mail with the hash are marked as spam. The hash is properly escaped in the query. Damaged codes in the process of encoding and decoding, maybe, i'm now tracking the code with logs. I will tell you. Thanks for your participation. Edited August 29, 2016 by lsard (see edit history) Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now