We use cookies to improve your experience. No personal information is gathered and we don't serve ads. Cookies Policy.

ExpressionEngine Logo ExpressionEngine
Features Pricing Support Find A Developer
Partners Upgrades
Blog Add-Ons Learn
Docs Forums University
Log In or Sign Up
Log In Sign Up
ExpressionEngine Logo
Features Pro new Support Find A Developer
Partners Upgrades
Blog Add-Ons Learn
Docs Forums University Blog
  • Home
  • Forums

Help with mysql_insert_id() ?

Development and Programming

WCW's avatar
WCW
6 posts
17 years ago
WCW's avatar WCW

Hi folks. I’m making good progress on an extension to help keep two different member info databases (one for EE, the other for our catalog system) synced up, changing the secondary db table when actions happen to the members data within EE. I’m jammed up a bit, however, trying to work with a hook labeled member_register_validate_members found in mod.member_register.php

I want to update a pending member to validated status in my secondary db table when folks self-validate using their emailed link. This link includes a unique authorization code passed in the url as id=xxxxxxxx This permits EE to identify the member and update their status within the member table. However, JUST before the hook, the script cleans up after itself and changes the authorization field back to “”.

How do I grab the username of this just changed record? I assume it would be done with mysql_insert_id() to grab the last record worked on, but I don’t know how to write the query. My non-working code (due to the just emptied authcode) is as follows:

function self_validate_other()
 {
  global $DB, $IN;
  $id  = $IN->GBL('id'); 
  $OurUsername = "";
  $query = $DB->query("SELECT username FROM exp_members WHERE authcode = '".$DB->escape_str($id)."'");
  $OurUsername = $query->row['username'];
  $DB->query("UPDATE APUsers SET RegistrationConfirmed = '1' WHERE UserName = '$OurUsername'");
 }

Any help would be much appreciated 😊

Mod Edit: Moved for you, to Extensions.

       
Daniel Walton's avatar
Daniel Walton
553 posts
17 years ago
Daniel Walton's avatar Daniel Walton

Hi WCW,

I’ve recently used the same hook, and to my despair ran into the same problem. I couldn’t see a suitable way out of it and decided that perhaps a feature request could be made to alter the position and/or data made available to extensions on that hook?

I ended up making a minor alteration to the core code (tut tut), moving the query (~line 939) to below the extension call.

mysql_insert_id() can only return data sent back if the query was an insert (with an auto_increment field), which of course this isn’t :(

       
Derek Jones's avatar
Derek Jones
7,561 posts
17 years ago
Derek Jones's avatar Derek Jones

Edit: Nevermind, I see the query the makes that variable’s usefulness go poof (goes to pour some coffee). Perhaps this hook could use some additional arguments. Either of you care to make a feature request?

       
Daniel Walton's avatar
Daniel Walton
553 posts
17 years ago
Daniel Walton's avatar Daniel Walton

/lazymode

       
WCW's avatar
WCW
6 posts
17 years ago
WCW's avatar WCW

Thanks fellas. The news isn’t particularly good, but at least I’m not missing something obvious. And, the_butcher has already posted a feature request - pretty good for a guy in /lazymode!

       

Reply

Sign In To Reply

ExpressionEngine Home Features Pro Contact Version Support
Learn Docs University Forums
Resources Support Add-Ons Partners Blog
Privacy Terms Trademark Use License

Packet Tide owns and develops ExpressionEngine. © Packet Tide, All Rights Reserved.