Hi,
When a user registers on our forum, I need the data that they submit (plus some other data that could be in hidden fields on the registration page) to be submitted to both the mysql database for the forum as well as our download systems mysql database.
I need to get the following fields into our download systems mysql database
Username
Password (unencrypted)
Email
Name (Null)
Validation: 1155660699406783
Status: Registered
ReceiveMail: Yes
SortField: Title
SortOrd: ASC
PerPage: 15
Grouping: 0
Could someone here kindly tell me what coding I would use to accomplish this?
Could it be as simple as putting an extra insert into (database_name) Username=username email=emailaddress name=null validation=1155660699406783 status=Registered ReceiveMail=Yes SortField=Title SortOrd=ASC PerPage=15 Grouping=0 ?????
If so, what would be the actual code to insert so that when the user hits the submit button to register on the forums it would also send this information to the second mysql database? And in what file would it go and where in the file would it go.
I really appreciate it if someone can help me with this. Some might thing it to be easier to just have the download system read from the SMF member database but I think thats much harder to start changing around the CGI files that run the database system if I can just write the users information to both the SMF mysql database as well as our download systems mysql database.
Thanks again if you can help. And I hope I posted this to the right forum, since I think converter is what Im trying to do, convert the user submitted into to my download systems mysql database.
Both mysql databases are on the same server (localhost) They just have different names for each database.
It is possible to do this. Not sure why you want to store unencrypted passwords. On register.php
foreach ($_POST as $key => $value)
{
if (!is_array($_POST[$key]))
$_POST[$key] = htmltrim__recursive(str_replace(array("\n", "\r"), '', $_POST[$key]));
}
add after
$copyToTable = db_query("
INSERT INTO `DB_NAME_HERE`.TABLE_NAME_HERE
(username, password, email, name, validation, status, receiveemail, sortfield, sortord, perpage, grouping)
VALUES ('$_POST[user]', '$_POST[passwrd1]', '$_POST[email]', 1155660699406783, 'Registered', 'Yes', 'ASC', 15, 0)", __FILE__, __LINE__);
if ($copyToTable === false)
'Was\'t able to copy data to other table';
Remember to change the field names and the table names. That was jsut a quick sketch.
Thanks for responding.
One last question. Can you tell me if I can use the same code you posted in the script that is used when a user changes his information on my SMF board, so that if he updates his profile information it will also update my other database as well. If so, which script and where to insert it?
Thanks very much for your help, it is greatly appreciated.
well you would have to use UPDATE table_x SET z = 'z', y = 'y' WHERE X = x
something like that. I'm on my cell so I can't make it too detailed. if you don't get what I posted just let me know.
Thanks I do understand what you are saying about using update instead of set, though after looking through the profile.php file Im not finding where I can place the update instruction.
Perhaps profile.php is not the file I should be putting the update instructions?
Put it in this function ModifyProfile2().
Okay, I dont think this is right, But I am trying.......
// Execute the modifications!
function ModifyProfile2()
{
global $txt, $modSettings;
global $cookiename, $context;
global $sourcedir, $scripturl, $db_prefix;
global $ID_MEMBER, $user_info;
global $context, $newpassemail, $user_profile, $validationCode;
loadLanguage('Profile');
// UPDATE table_x SET z = 'z', y = 'y' WHERE X = x
$copyToTable = db_query("
UPDATE `database1`.Users WHERE 'Username' = $user_profile[$memID]['memberName'] SET
(Password, Email)
VALUES ('$newpassemail', '$_POST[email]')", __FILE__, __LINE__);
if ($copyToTable === false)
'Was\'t able to copy data to other table';
/* Set allowed sub-actions.
The format of $sa_allowed is as follows:
I must not be doing this right.
Ok in Profile.php find
// Do you have a *secret* password?
if (isset($_POST['secretAnswer']) && $_POST['secretAnswer'] != '')
$profile_vars['secretAnswer'] = '\'' . md5($_POST['secretAnswer']) . '\'';
Add after
if (isset($profile_vars['emailAddress']) || isset($profile_vars['passwd']))
{
$email = isset($profile_vars['emailAdress']) ? $profile_vars['emailAddress'] : $_POST['emailAddress'];
$password = isset($profile_vars['passwd']) ? $profile_vars['passwd'] : $_POST['passwrd1'];
$copyToTable = db_query("
UPDATE `database1`.Users
SET
Password ='$password',
Email = '$email'
WHERE 'Username' = '$old_profile[realName]'", __FILE__, __LINE__);
if ($copyToTable === false)
echo 'Was\'t able to copy data to other table';
}
Thanks, I tried that but I get a message that says something like "Hacking Attempt" or something to that effect.
I did copy and paste so I dont think I messed it up somewhere on my end.
Try changing
WHERE 'Username' = '$old_profile[realName]'", __FILE__, __LINE__);
to
WHERE Username = '$old_profile[realName]'", __FILE__, __LINE__);
Still get the Hacking Attempt message.
But I just thought of something else. The reason why I wanted to put this into the profile.php file is because when existing users change their email and or password then it gets written to the other database, but being that I have an existing 485 users, I was hoping that I could just tell them to go update their profiles and then it would do either.... 1. Update their email and or password in the 2nd database, or 2. Create their username, password etc like from what your first bit of coding did for us.
So really I guess what I would need would be for the profile.php file to do is to check the 2nd database when writing the users information and if the member does not exist in the 2nd database, then it will write the members information in there, and if the member does exist in the 2nd database, then it will just update the information.
By the way, what triggers this "Hacking Attempt" message?
Can you post your Profile.php?
About the other thing I'll see what would be the best way to do it.
Since it's too big to paste into a message and this forum doesnt allow attachments, then you can find it here:
http://www.softwareparade.com/smf/profile.zip
Okay, through carefull manipulation of the smf members database and mysql commands I've managed to import all existing users into my 2nd database using their existing membername and email address from the smf_members database and assigning a new password on the 2nd database that uses the 10 digit time registered field from smf_members. So I really dont need it to check the 2nd database to see "if user exists update, else insert" at all. This way I will send out a mass email from my 2nd database system to all registered users informing them of their new database login username and "password" and giving them a link to go change it if they like.
Since all users have now been imported into the 2nd database, then all I really need is a way for the profile.php to alter the 2nd databases information with the updated email address and password (password stored in 2nd database unencrypted) without getting the Hacking Attempt message when they update their Forum profile.
By they way, thanks for the help so far, it is really appreciated.
Here you go. You put the closing } in the wrong place.
Quote from: Jay The Code Monkey on August 19, 2006, 10:56:08 PM
Here you go. You put the closing } in the wrong place.
Still getting the "hacking attempt....." message. i've reuploaded the attached Profile.php that you included in your message but still..... Hacking Attempt.
Ughhh. I'll look more into this late ron today.
Does the code on registrtaion page work fine?
Yes, it's been adding new members to the 2nd database.
Post the Register.php file also. Want to check something out.
Okay, it's at http://www.softwareparade.com/smf/Register.zip
Try this.
Thanks,
I get this error just by clicking on the Profile link to the Profile.php file.
Parse error: parse error, unexpected T_IF in /home/site1/public_html/Sources/Profile.php on line 815
Line 815 has: if ($copyToTable === false)
This happens just by clicking the link to view a profile. No profile is shown, instead the error message is shown instead of the normal profile itself.
Sorry forgot a ; in the line before that one.
I really hate to say this, since you've been trying so hard to help me out with this but.....
An Error Has Occurred!
Hacking attempt...
message pops up with the Profile.php file you just attached.
You get the error while viewing the page or when you save the profile?
When trying to save the profile.
I had thought it might be because I am logged in with one of my administrator accounts, but I just tried it being logged in as a regular member, and it produced the same hacking attempt message.
Try this.
Quote from: Jay The Code Monkey on August 21, 2006, 05:01:25 PM
Try this.
Oh boy, you are the best!
I really can't express how thankfull I am. It works perfectly now.
Perhaps you can tell me what all you had to do to get this working so that when final release comes around for SMF, then I can duplicate it if the profile.php file has to be overwritten.
Thanks again.
CB.
I added backticks (`) on the table names. Seems like since some of those column names are part of the reserved words for MySQL they need to be n ticks.