This topic is locked
[SOLVED]

 how to save the username in another table

4/13/2010 2:54:00 PM
PHPRunner General questions
A
alexandra author

Dear gents, this must be a very simple question for some of you (I hope)
I want to create a new record (in another table than the user-regitration table) during the registration process.

but I have tried all that I could find in the manual on the forum etc.
this is the (last) code I used for the event (from many): I want to to use the username after succesfull registration and store this in the clmain table, in the field UserID
global $conn;

$strSQLInsert = "insert into clmain (UserID) values SESSION(username))";

db_exec($strSQLInsert,$conn);
I hope someone can help me out ( I am learning)
thank you in advance?

D
Dale 4/13/2010

Try something like below
global $conn;

$strSQLInsert = "insert into clmain (UserID) values ('".$_SESSION["username"]."')";

db_exec($strSQLInsert,$conn);
NOTE: Really focus on the syntax, round brackets, square brackets, single quotes and double quotes all mean different things to the statement.
Hope that works for you.

A
alexandra author 4/14/2010

I already send you a PM, but at the moment of registration there is no session ID, I guess. When I used the username from the session it created an empty record.

How can I get the username from the registration form in another table?

the challenge remains.
appreciate your help

D
Dale 4/14/2010

Sorry, I just assumed you had the value you needed in the $_SESSION["UserID"] variable.

I dont use a registration page in my apps so I have never set that up. I am assuming that you have a table with username as a field for users to login.
So just add this line in the AfterSuccessfulRegistration event above the insert you have there already.
$_SESSION["UserID"] = $userdata["username"];
global $conn;

$strSQLInsert = "insert into clmain (UserID) values ('".$_SESSION["username"]."')";

db_exec($strSQLInsert,$conn);
Hope that helps.

A
alexandra author 4/15/2010

Oeps (on one side I am happy that its not a simple fix. After all my hours of trying) I would hate to see someone demonstrate that I waisted a lot of time :-)

I tried the code below as suggested, but again an empty record, no username transferred (&&^^%$%&^*@!@!#) to put it politely
$_SESSION["UserID"] = $userdata["username"];
global $conn;

$strSQLInsert = "insert into clmain (UserID) values ('".$_SESSION["username"]."')";

db_exec($strSQLInsert,$conn);
maybe my approach is to complicated I want to limit users to create only one record ( no add record option) I thought it would be easy to just create that record during registration and have no add record on the menu.

Maybe my solution is to simple :-)

D
Dale 4/15/2010

Going to try one more thought for you.

The problem seems to be, we are not sure if the $_SESSION["UserID"] is being filled properly.
Try printing the registration variables and see what is there. Perhaps we are grabbing the wrong userdata variable
try
$_SESSION["UserID"] = $userdata["username"];

echo "what is session UserId ".$_SESSION["UserID"];

print_r ($userdata);
// global $conn;

// $strSQLInsert = "insert into clmain (UserID) values ('".$_SESSION["username"]."')";

// db_exec($strSQLInsert,$conn);
Remark out (as above ) the insert stuff temporarily until you can proove that you are getting the session UserID variable filled.

when you run this, you should see what the current $_SESSION["UserID"] is and then what the $userdata["field names"] and their data is.

If you see the username data you are looking for in there, note the field name and replace the $userdata["username"] with the correct field name.
This should show you what is going on.

Sorry, but as I said earlier I have never used the registration page so I have nothing here to test with.

If you see the issue, test it as above, and then remove the // remarks and remark out the echo and print_r lines.
It is doable, its just finding the right field name to use to fill the $_SESSION["UserID"]

Hope this helps

A
alexandra author 4/15/2010

Dear DaleM, Happy you don't give up so easily, and this test should be giving the answer (normally)
This is what I got returned:
what is session UserId caterineArray ( [username] => caterine [password] => caterine00 [email] => testemail@hotmail.com [fullname] => test [active] => 0 )
According to your explanation, you have been giving me the right code al along, but somehow it is not being stored in the table, the table is working for sure. Since i can create/add records via other forms.

with the following code:
$_SESSION["UserID"] = $userdata["username"];
global $conn;

$strSQLInsert = "insert into clmain (UserID) values ('".$_SESSION["username"]."')";

db_exec($strSQLInsert,$conn);
I do get an empty record in clmain

A
alexandra author 4/15/2010



Dear DaleM, Happy you don't give up so easily, and this test should be giving the answer (normally)
This is what I got returned:
what is session UserId caterineArray ( [username] => caterine [password] => caterine00 [email] => testemail@hotmail.com [fullname] => test [active] => 0 )
According to your explanation, you have been giving me the right code al along, but somehow it is not being stored in the table, the table is working for sure. Since i can create/add records via other forms.

with the following code:
$_SESSION["UserID"] = $userdata["username"];
global $conn;

$strSQLInsert = "insert into clmain (UserID) values ('".$_SESSION["username"]."')";

db_exec($strSQLInsert,$conn);
I do get an empty record in clmain
I need to share another thought to see if this could affect the code functioning. In the user registration table there is one field called " active ", this field is set from 0 to 1 when the users clicks a link that is send by email to activate his/her account, could this affect the procedure of writing in another table?
nasty puzzle for sure.

D
Dale 4/15/2010

Great, feedback. Try,
$_SESSION["UserID"] = $userdata["username"];
global $conn;

$strSQLInsert = "insert into clmain (UserID) values ('".$_SESSION["UserID"]."')";

db_exec($strSQLInsert,$conn);
Not sure about the Active thing you mention. Lets get the table updated first. Then we can see what other info you would like to insert into that other table.

G
gawde 4/15/2010



Great, feedback. Try,
$_SESSION["UserID"] = $userdata["username"];
global $conn;

$strSQLInsert = "insert into clmain (UserID) values ('".$_SESSION["UserID"]."')";

db_exec($strSQLInsert,$conn);
Not sure about the Active thing you mention. Lets get the table updated first. Then we can see what other info you would like to insert into that other table.



If I may add my 2 cents - Is the (UserID) field in the clmain table defined as an integer (or some other form of numeric field)? MySQL (I'm assuming) will not allow text type data to be placed into a numeric field. Hope it's that simple.

A
alexandra author 4/15/2010

Whohaaaaaaaaaaaaaa !!!!!!!!!!!!

Thank you Dale!
works like a charm, I can now limit profiles of registering members to 1 record only.

still trying to understand how you got $_SESSION["UserID"] from the registration form (UserId is not in that table, but it works).
<img src='https://asprunner.com/forums/file.php?topicimage=1&fieldname=reply&id=49187&image=1&table=forumreplies' class='bbc_emoticon' alt=':D' />


now I will go for my next challenge, sending a record (memo) to mutiple members of the sportsclub that have indicated to be interested in (same of) various sports.

I'will be working on that one hopefully shorter then a about 7 nights.
Thank you for your great help

D
Dale 4/15/2010

Glad to see it worked. You could get the job done without a session variable by using the following,
global $conn;

$strSQLInsert = "insert into clmain (UserID) values ('".$userdata["username"]."')";

db_exec($strSQLInsert,$conn);
But if its working, great. It is a pretty safe method using the session variable to store the username.