Whats going on with this PHP code.

Questions about programming languages and debugging
Post Reply
User avatar
visser
Fame ! Where are the chicks?!
Fame ! Where are the chicks?!
Posts: 472
Joined: 03 Apr 2007, 16:00
17
Location: online
Contact:

Whats going on with this PHP code.

Post by visser »

hey all. ive been working on my website and found some open source software stuff that takes care of most if not all of what we need to do. So right now its just a matter of adjusting the front end to look the way we want it to look.
what im having troubles with is this join script that is provided. I was able to figure out a solid portion of it to the point where i can understand the whole idea behind it.

right now when it creates a new user it inserts into the profiles table. what i want it to do is to not only insert into the profiles table but another table as well. im not to worried about it, i just need a look over as to whats going on with the following script.
im not looking for what each variable is, more of what seach little thing does to the variables.
hopefully that makes sense.

http://code.suck-oold.com/32


if you dont want to explain the whole code thats fine, jsut suggest a place where i could put my own little snippet that would insert my own stuff into a database. I need it set so that everytime it creates a new profile it also puts some other stuff into the database, and its the same stuff every time a profile is created.

thanks for everything guys! and girl

User avatar
bad_brain
Site Owner
Site Owner
Posts: 11636
Joined: 06 Apr 2005, 16:00
19
Location: In your eye floaters.
Contact:

Post by bad_brain »

hm, I am not the king of PHP, and I also have not enough time to really analyze the script, but the comments in the script give already a basic idea.

it's very hard to analyze a script anyway when not having the full source of all related files.... :wink:

User avatar
uid0
Fame ! Where are the chicks?!
Fame ! Where are the chicks?!
Posts: 106
Joined: 08 Jun 2008, 16:00
15
Contact:

Post by uid0 »

I'm not so sure I see what you want to do exactly..

"what i want it to do is to not only insert into the profiles table but another table as well."

Do you want to save the new user profile in another table besides Profiles? or do you want that, besides adding the new user on Profiles, a new table is created? or do you just want the user be saved on other table?

If is the first one then you'll need to make a copy of the code starting at line 193:

Code: Select all

$sSet = $this -> collectSetString( $aNewProfile );
$sQuery2 = "INSERT INTO `OtherTable` SET \n$sSet";
$rRes2 = db_res( $sQuery2 );
Then you could change the "if" starting at line 201 not only to check one query but two:

Code: Select all

if( ($rRes) && ($sRes2) ) {
....
Now, as for all the script, it's complicated to explain it since the main class is missing, we only know on of the functions on it, but, basically:

The function will create or check if exists, a profile in a DB, the data used to has to be passed to the function from other part of the script that isn't posted in that code you gave or from another file, in any case, the function will, initially, work to create a new user, you notice this because the first line:

Code: Select all

function createProfile( $aData, $bSendMails = true, $iMainMemberID = 0 )
This is basically telling the script that $aData is an array of new data (don't exist in the db), also that, since is a new user, a mail will be send to activate his account and the $iMainMemberID = 0 will by default set the users as not existent although later in the function if this is true or not will be checked.

However, those are default values that can be overridden when the function is called but will only return true if the data send in the script exist in the DB (an user exists).

The line 5 if the array ($aData) isn't empty, if so, the script returns null.

At line 39 the script checks if the the user ID is set, if so, the script calls a function to collect the profile data regarding to that user ID, if no data is returned (cause the user don't exists) the id is set to null so can be generated later.

At line 51 start the build of a new user, from that line to the 189 all new user data is collected (the Name selected by the user, a profile id is generated using the function genUniqueValue, the password is also generated wan so on.

At line 193 the data is ready to be inserted on the DB, after that, in line 201 the script check if the insertion in the DB was successful, if so, the script assigns an ID to the user, then, the script checks if users need to activate their accounts (line 221), if so, an email is sended and a text will be displayed with the status of that action (mail was send or not...)

Finally, the profile is updated with an encrypted password.

Maybe this don't answer your question, if so, my apologizes, I might misunderstand what you want to know about the script.



Regards

Post Reply