User registration to a second database
I am creating a game site for my girlfriends son for the World of Warcraft game. I want drupal to create the user in a second database not related to the web site at same time. I have partly got this working, when you create an account on drupal it creates the account in the second database (which is used for the game). The problem is during the create account procedure it has a radio button selection that you have one of 3 choices (WOW, WOW - TBC, WOW - WOTLK) that would place one of three numeric values into the second database the problem is it always puts the numeric value 0 in the database regardless of which one is selected. And me not being a programmer I am not sure how to fix this. I am including parts of the php function I believe to be related, for the whole module is 260+ lines and didn't think it to be appropriate to post the whole thing here. If someone can point me in the right direction on how to fix this it would be greatly appreciated.
case 'register':
// Add a fieldset containing radio buttons
// to the user registration form.
$fields['wow_client'] = array(
'#type' => 'fieldset',
'#title' => 'WOW Client Selection'
);
$fields['wow_client']['answer'] = array(
'#type' => 'radios',
'#description' => 'Select your WOW client',
'#required' => 'TRUE',
'#default_value' => 1,
'#options' => array( 'WOW', 'WOW - TBC', 'WOW - WOTLK' )
);
return $fields;
break;
// Check for duplicate IP's and deny if found.
case 'validate':
if( !$user->uid ) {
$msg = '';
if( isset( $edit['answer'] ) == '0' ) {
$edit['answer'] = '0';
}
elseif( isset( $edit['answer'] ) == '1' ) {
$edit['answer'] = '8';
}
if( isset( $edit['answer'] ) == '2' ) {
$edit['answer'] = '44';
}
}
return;
break;
// Export form dara and create a wow account
// Grab password before it's encrypted so we can use SHA1
case 'insert':
foreach ( $edit as $key => $value ) {
switch ( $key ) {
case 'pass':
$wowpass = $value;
break;
case 'roles':
if ( $user->uid ) {
$gm = thunderfist_roles( $value );
}
break;
}
}
// Insert account information into the logon database
db_set_active( 'logon' );
db_query( "INSERT INTO TFlogon.accounts (acct, login, password, encrypted_password, gm, lastip, email, flags) values (%d, '%s', '%s', '%s', '%s', '%s', '%s', '$edit['answer']')",
$account->uid, $account->name, $wowpass, SHA1(strtoupper(
$account->name).':'.strtoupper( $wowpass ) ), $gm, $user->hostname,
$account->mail, $user->flags );
db_set_active( 'default' );
db_query( " UPDATE users SET access = %d where uid = %d", time(), $account->uid );
db_set_active( 'default' );
break;
Issue is with
Issue is with
'$edit['answer']'in the insert, it should be$edit['answer'](no single quotes around the it)I have tried this, and it is
I have tried this, and it is still not working. It produces the error
Parse error: syntax error, unexpected T_ENCAPSED_AND_WHITESPACE, expecting T_STRING or T_VARIABLE or T_NUM_STRING in /home/jkraz/htdocs/sites/all/modules/thunderfist/thunderfist.module on line 60I put the single quotes back in and it works with exception of putting contents of $edit['answer'] in the database.
I did not read close enough,
I did not read close enough, this
db_query( "INSERT INTO TFlogon.accounts (acct, login, password, encrypted_password, gm, lastip, email, flags) values (%d, '%s', '%s', '%s', '%s', '%s', '%s', '$edit['answer']')",$account->uid, $account->name, $wowpass, SHA1(strtoupper(
$account->name).':'.strtoupper( $wowpass ) ), $gm, $user->hostname,
$account->mail, $user->flags );
should be
db_query( "INSERT INTO TFlogon.accounts (acct, login, password, encrypted_password, gm, lastip, email, flags) values (%d, '%s', '%s', '%s', '%s', '%s', '%s', '%s')",$account->uid, $account->name, $wowpass, SHA1(strtoupper(
$account->name).':'.strtoupper( $wowpass ) ), $gm, $user->hostname,
$account->mail, $user->flags, $edit['answer'] );
Could the problem be in the
Could the problem be in the validate section, I did as you suggested above with same result. The validate section reads
case 'validate':if( !$user->uid ) {
$msg = '';
if( isset( $edit['answer'] ) == '0' ) {
$edit['answer'] = '0';
}
elseif( isset( $edit['answer'] ) == '1' ) {
$edit['answer'] = '8';
}
if( isset( $edit['answer'] ) == '2' ) {
$edit['answer'] = '44';
}
}
return;
break;
My thinking here is that even though the default radio button is set to 1 that the $edit['answer'] is not being set to the according number depending on what you select and is writing 0 to the database every time.
I believe the problem is in
I believe the problem is in the insert section due to process of elimination. I changed the validate section to read:
<?php>
case 'validate':
if( !$user->uid ) {
$msg = '';
if( isset( $edit['decision'] ) && $edit['decision'] == '0' ) {
$client_flags = '0';
}
elseif( isset( $edit['decision'] ) && $edit['decision'] == '1' ) {
$client_flags = '8';
}
if( isset( $edit['decision'] ) && $edit['decision'] == '2' ) {
$client_flags = '44';
}
}
return;
break;
?>
I tested it by adding a echo "$client_flags"; under the $client_flags = '0'; $client_flags = '8'; $client_flags = '44'; and tried all 3 of them and it echoed the appropriate number to the screen. No matter what I seem to do it still only writes a 0 to the database. I am including the full function by chance it something that I am either not understanding or something else causing the function not to write the correct number to the database. I have tried changing the last '%s' to $edit['decision'] and '$edit['decision']' and "$edit['decision']" as well as '$client_flags' and $client_flags and "$client_flags" tried changing the last '%s' to %s all still only wrote 0 to the database for the flags. I am quite sure this is my misunderstanding of php. The full function reads:
<?php>
function thunderfist_user($op, &$edit, &$account, $catagory = NULL) {
global $user;
switch( $op ) {
// The User is Registering
case 'register':
// Add a fieldset containing radio buttons
// to the user registration form.
$fields['wow_client'] = array(
'#type' => 'fieldset',
'#title' => 'WOW Client Selection'
);
$fields['wow_client']['decision'] = array(
'#type' => 'radios',
'#description' => 'Select your WOW client',
'#required' => 'TRUE',
'#default_value' => 1,
'#options' => array( 'WOW', 'WOW - TBC', 'WOW - WOTLK' )
);
return $fields;
break;
// Check for duplicate IP's and deny if found.
case 'validate':
if( !$user->uid ) {
$msg = '';
if( isset( $edit['decision'] ) && $edit['decision'] == '0' ) {
$client_flags = '0';
}
elseif( isset( $edit['decision'] ) && $edit['decision'] == '1' ) {
$client_flags = '8';
}
if( isset( $edit['decision'] ) && $edit['decision'] == '2' ) {
$client_flags = '44';
}
}
return;
break;
// Export form data and create a wow account
// Grab password before it's encrypted so we can use SHA1
case 'insert':
foreach ( $edit as $key => $value ) {
switch ( $key ) {
case 'pass':
$wowpass = $value;
break;
case 'roles':
if ( $user->uid ) {
$gm = thunderfist_roles( $value );
}
break;
}
}
// Insert account information into the logon database
db_set_active( 'logon' );
db_query( "INSERT INTO TFlogon.accounts (acct, login, password, encrypted_password, gm, lastip, email, flags) values (%d, '%s', '%s', '%s', '%s', '%s', '%s', '%s')",
$account->uid, $account->name, $wowpass, SHA1(strtoupper(
$account->name).':'.strtoupper( $wowpass ) ), $gm, $user->hostname,
$account->mail, $account->flags, $client_flags );
db_set_active( 'default' );
db_query( " UPDATE users SET access = %d where uid = %d", time(), $account->uid );
db_set_active( 'default' );
break;
// Update the login, password, banned info, wow client in the logon when user updates drupal information.
case 'update':
if( isset( $edit['name'] ) ) {
$login = $edit['name'];
}
if( isset( $edit['pass'] ) && !empty( $edit['pass'] ) ) {
$newpass = $edit['pass'];
}
if( isset( $edit['decision'] ) ) {
$client_flags = $edit['decision'];
}
else {
db_set_active( 'logon' );
$newpass = db_result( db_query( "SELECT password FROM TFlogon.accounts where acct = %d", $account->uid ) );
db_set_active( 'default' );
}
if( $edit['status'] ) {
$banned = 0;
}
else {
$banned = $edit['status'];
}
if( isset( $edit['roles'] ) ) {
$rid = 0;
foreach( $edit['roles'] as $role ) {
if( $role > $rid ) {
$rid = $role;
}
}
$gm = thunderfist_roles( $rid );
}
else {
$rid = db_result( db_query( "SELECT max(rid) from users_roles where uid = %d", $account->uid ) );
$gm = thunderfist_roles( $rid );
}
thunderfist_updateinfo( $login, $newpass, $gm, $banned, $flags, $account->uid );
break;
// Delete user account from the logon database
case 'delete':
thunderfist_deleteaccount( $account->uid );
break;
}
}
?>
I am not sure what else to do to fix this problem, if anyone else has any suggestions it would be greatly appreciated.