
rado
Posts: 221
|
| Posted: 10/24/2008, 12:26 PM |
|
After registration of user the page will be redirected to "Thank You" page that will give user message which include user name and email address. The problem that I discover is that after every new registration I'm always getting the same (old) user name and email address , not the the current (that was just registered).
Thank you very much for any kind of help.
Rado
|
 |
 |
Gena
Posts: 591
|
| Posted: 10/24/2008, 12:39 PM |
|
Are you sure that you pass correct parameters to CCDLookUp ?
please, post your code here
_________________
Gena |
 |
 |
rado
Posts: 221
|
| Posted: 10/24/2008, 12:43 PM |
|
//Custom Code @13-2A29BDB7
function Header_BeforeShow(& $sender) {
global $Header;
global $Connection_rr_db;
$Header->UserName->SetValue(CCDLookUp("first_name","user_login=". $Connection_rr_db->ToSQL(CCGetUserID(), ccsInteger), $Connection_rr_db) );
}
//End Custom Code
Thanks for fast replay.
|
 |
 |
Gena
Posts: 591
|
| Posted: 10/24/2008, 1:10 PM |
|
1. what is user_login field?
2. I can't see Table parameters....
CCDLookUp(ColumnName, TableName, Where, Connection)
you have just CCDLookUp(ColumnName, Where, Connection)
check this
_________________
Gena |
 |
 |
rado
Posts: 221
|
| Posted: 10/24/2008, 1:25 PM |
|
OK,
I would like to retrieve two columns ("user_login" and "first_name") from table "users" using "Connection_rr_db"
Thanks a lot
|
 |
 |
rado
Posts: 221
|
| Posted: 10/24/2008, 1:26 PM |
|
My primary key is "user_id"
|
 |
 |
Gena
Posts: 591
|
| Posted: 10/24/2008, 1:33 PM |
|
ok
it should be like this
$Header->UserName->SetValue(CCDLookUp("first_name", "users", "user_id=". $Connection_rr_db->ToSQL(CCGetUserID(), ccsInteger), $Connection_rr_db) );
similar for the "user_login"
_________________
Gena |
 |
 |
rado
Posts: 221
|
| Posted: 10/24/2008, 1:37 PM |
|
Do I have to have write separate DDCLookup for every single columns?
|
 |
 |
Gena
Posts: 591
|
| Posted: 10/24/2008, 1:46 PM |
|
Quote rado:
Do I have to have write separate DDCLookup for every single columns?
Not at all.
Retrieves a single database value which can be a field or an expression. So you can try to put some sql expression like
CONCAT_WS(' - ','user_login','first_name')
_________________
Gena |
 |
 |
rado
Posts: 221
|
| Posted: 10/24/2008, 2:02 PM |
|
Ohhh, Thank you Gena so much. I'm getting results, however the retrieved user name is random. Is not the user that was just registered. I'm looking for name of the user that has just finished registration before redirecting to Thankyou" page. Do you have any idea why I'm getting wrong information?
Thanks again
|
 |
 |
Gena
Posts: 591
|
| Posted: 10/24/2008, 2:21 PM |
|
CCGetUserID returns user ID of logged in user so if your user is just registered it possible that he not yet logged in... So CCGetUserID return some old value. So check this
_________________
Gena |
 |
 |
Gena
Posts: 591
|
| Posted: 10/24/2008, 2:27 PM |
|
I think in your case you don;t need (o ever you can't) to use CCGetUserID. You need to use something like this to get last inserted user_id
$SQL = "SELECT LAST_INSERT_ID() FROM users";
$db->query($SQL);
if ($db->next_record()) {
$last_user_id = $db->f(0);
}
and now you can use $last_user_id ....
_________________
Gena |
 |
 |
Gena
Posts: 591
|
| Posted: 10/24/2008, 2:27 PM |
|
LAST_INSERT_ID() is for mySQL...
_________________
Gena |
 |
 |
rado
Posts: 221
|
| Posted: 10/24/2008, 7:16 PM |
|
Gena,
I try so many different things and at the end once I remove all test users the problem disappeared. I don't have any idea what happend, but now everything works just fine.
Thank you very much for your help. Since I'm newbie, I will probably need more help, so I will keep in my mind your effort and sometimes come up gladly with donation.
Thanks, again
|
 |
 |
melvyn
Posts: 333
|
| Posted: 10/24/2008, 7:30 PM |
|
As Gena told you, the CCGetUserID() will work for logged users, so as the user isn't logged, you must try in another way to get your query working
You need two queries: the first one to get the last id and the the second one to get the user name.
First get the id as Gena told you. Or, you can, also, use max(id) instead of last_insert_id() which work in mysql only.
$last_id = CCDlookUp("max(user_id)","users",$Connection_rr_db);
The above code will get the last id. See the empty where condition. There's no where, you simply select the last inserted. That's useful for your question. After that, you can try in one single query:
$last_id = CCDlookUp("max(user_id)","users",$Connection_rr_db);
$sql = "SELECT user_login, first_name FROM users WHERE user_id = $last_id";
if ($db->next_record()) {
$last_user_id = $db->f("user_id"); // (same as $last_id provided).
$last_user_login = $db->f("user_login");
$last_user_name = $db->f("user_name");
}
echo "Thank you ".$last_user_name." Your login is: ". $last_user_login;
There's another way. In the AfterInsert event, you still have the user login and password (I guess), so you can say:
$login = $Component->your_form->user_login->GetValue();
$password $Component->your_form->the_password->GetValue();
CCLoginUser($login,$password);
//Now let's use your original code:
$user_name = CCDlookUp("user_name","users","user_id = ".CCGetUserID(),$$Connection_rr_db);
echo $user_name;
_________________
Melvyn Perez
Puro Codigo
http://purocodigo.com |
 |
 |
rado
Posts: 221
|
| Posted: 10/24/2008, 7:39 PM |
|
Thank Melvyn for detailed explanation.
Rado
|
 |
 |
DonP
|
| Posted: 10/25/2008, 8:59 AM |
|
Using max(user_id) will work just fine as long as there is no
possibility of two people registering at the same time. If that
possibility exists, it might provide the wrong one. Also, a WHERE is
still needed for CCDLookUp, so something line this should act as a
filler for the parameter:
$last_id = CCDlookUp("max(user_id)","users","user_id IS NOT NULL",
$Connection_rr_db);
Using LAST_INSERT_ID() is better although I believe it will work only
when your visitor is still on the registration page so, if the Thank You
page is separate, a session would have to be set on the registration
page to make use of it. For example:
$SQL = "SELECT LAST_INSERT_ID() FROM users";
$db->query($SQL);
if ($db->next_record()) {
CCSetSession("NewUserID",$db->f(0)");
}
then a CCDLookUp on the Thank You page using
CCGetSession("NewUserID","") in the WHERE clause.
On the other hand, you may simply be able to get the user name field
directly from the form submission without any DB at all:
CCGetParam("first_name", "");
Since a form was just submitted with values passed, you should be able
to pick up this value on the Thank You page.
Don (DonP)
|
|
|
 |
melvyn
Posts: 333
|
| Posted: 10/25/2008, 10:55 AM |
|
Quote :Using max(user_id) will work just fine as long as there is no possibility of two people registering at the same time. If that possibility exists, it might provide the wrong one.
There's always that possibility. The best workaround to fix that is set a session variable when starting and using it in the where.
Anyways, the possibility of two users clicking "next" at exactly the same time is far remote. I've setup similar environments to catch "the last record" inside an order aprobal system. When a user catch this record no more users can take it again. I use the max(id). Thousands of orders per day, average of 50 - 80 users introducing new records and 25 users opening to aprove them (theese ones uses de max(id)). I don't have issues.
So, forget the possibility of two users at the same time if he don't have 1,000,000 users per day and registration of 1,000 per hour.
If his application is for something like that, I'm pretty sure that he will not ask such question here.
The last of your recommendations is pretty good, the best one. Catching from url is just a master's solution! lol
Try that rado.
_________________
Melvyn Perez
Puro Codigo
http://purocodigo.com |
 |
 |
rado
Posts: 221
|
| Posted: 10/27/2008, 6:14 PM |
|
Thanks everybody for help, Since I'm really new with CodeChargeStudio I would like to ask you for a little bit more instruction...
=========================================================
$last_id = CCDlookUp("max(user_id)","users","user_id IS NOT NULL",
$Connection_rr_db);
=========================================================
QUESTION: Do I need to use this if I use "LAST_INSERT_ID()" described bellow? If yes which event and on which page. registration or Thankyou page?
==========================================
$SQL = "SELECT LAST_INSERT_ID() FROM users";
$db->query($SQL);
if ($db->next_record()) {
CCSetSession("NewUserID",$db->f(0)");
}
===========================================
QUESTION: Which even to use for this? After Insert? or? I understood that this needs to be done on the registration page. Is that correct
===============================================
then a CCDLookUp on the Thank You page using
CCGetSession("NewUserID","") in the WHERE clause.
===============================================
QUESTION: should I use "After Insert" event as well?
Thanks a lot
Rado
|
 |
 |
melvyn
Posts: 333
|
| Posted: 10/27/2008, 7:12 PM |
|
AfterInsert
Of course you need in the first page, because in that one you're using the returning value to send to the another page.
Anyways, use the DonP sugestion, is better, faster, and zero query.
_________________
Melvyn Perez
Puro Codigo
http://purocodigo.com |
 |
 |
rado
Posts: 221
|
| Posted: 10/28/2008, 6:09 AM |
|
First again I would like to thank you for help and specially for patient with me. I think that I'm close, however it still doesn't work.
Here is part of code of Registration page:
===============================================
//Custom Code @40-2A29BDB7
// -------------------------
global $Redirect;
$Redirect = "Thankyou.php";
$login = $Component->user_login->GetValue();
$password = $Component->user_password->GetValue();
CCLoginUser($login,$password);
//End Custom Code
//Custom Code @42-2A29BDB7
// -------------------------
$SQL = "SELECT LAST_INSERT_ID() FROM users";
$db->query($SQL);
if ($db->next_record()) {
CCSetSession("NewUserID",$db->f(0));
}
// -------------------------
//End Custom Code
//Close users_AfterInsert @4-11208659
return $users_AfterInsert;
}
//End Close users_AfterInsert
===================================================
and here is part od code from Thankyou page:
===================================================
//Thankyou_Grid_BeforeShow @4-7EC63753
function Thankyou_Grid_BeforeShow(& $sender)
{
$Thankyou_Grid_BeforeShow = true;
$Component = & $sender;
$Container = & CCGetParentContainer($sender);
global $Thankyou_Grid; //Compatibility
//End Thankyou_Grid_BeforeShow
//Custom Code @13-2A29BDB7
//function Header_BeforeShow(& $sender) {
//global $Header;
//global $Connection_rr_db;
// $Header->UserName->SetValue(CCDLookUp("user_login","users","user_id=". $Connection_rr_db->ToSQL(CCGetUserID(), ccsInteger), $Connection_rr_db) );
}
//End Custom Code
//DLookup @15-2D28009C
global $DBConnection_rr_db;
$Page = CCGetParentPage($sender);
$ccs_result = CCDLookUp(user_login, users, CCGetSession("NewUserID",""), $Page->Connections["Connection_rr_db"]);
$ccs_result = strval($ccs_result);
$Container->user_login->SetValue($ccs_result);
//End DLookup
//Close Thankyou_Grid_BeforeShow @4-84E70E41
return $Thankyou_Grid_BeforeShow;
}
//End Close Thankyou_Grid_BeforeShow
When I run registration I'm getting this error:
"Fatal error: Call to a member function on a non-object in C:\Program Files\Apache Software Foundation\Apache2.2\htdocs\kw4rent_oct_27_2008\Registration_events.php on line 99"
The line 99 of registration page is:
"$db->query($SQL);"
Any suggestion?
Rado
|
 |
 |
Gena
Posts: 591
|
| Posted: 10/28/2008, 6:43 AM |
|
you have missed connection name declaration like
$db = new clsDByour connectionnamehereDB();
....
$SQL = "SELECT LAST_INSERT_ID() FROM users";
$db->query($SQL);
if ($db->next_record()) {
CCSetSession("NewUserID",$db->f(0));
}
//also goog to close it
$db->close();
_________________
Gena |
 |
 |
rado
Posts: 221
|
| Posted: 10/28/2008, 7:45 AM |
|
Thanks,
Now, there is no more errors, however I'm still getting random (already registered user) from database.
Rado
|
 |
 |
Gena
Posts: 591
|
| Posted: 10/28/2008, 9:43 AM |
|
what is Thankyou_Grid ? Why do you use grid?
Just use page, put some Labels and use BeforeShow event...
_________________
Gena |
 |
 |
rado
Posts: 221
|
| Posted: 10/28/2008, 2:10 PM |
|
Thanks Gena,
I recreate Thankyou, however I'm getting same (old results). I'm really sorry for your wasted time wtih me.
Thanks again
|
 |
 |
Gena
Posts: 591
|
| Posted: 10/28/2008, 2:40 PM |
|
No problem
try to trace if you get correct valure:
$db = new clsDByour connectionnamehereDB();
....
$SQL = "SELECT LAST_INSERT_ID() FROM users";
$db->query($SQL);
if ($db->next_record()) {
$NewUserID = $db->f(0) ;
echo $NewUserID;
}
//also goog to close it
$db->close();
so you will see your actual $NewUserID -go to your database tabe and check if this is correct value.
_________________
Gena |
 |
 |
Gena
Posts: 591
|
| Posted: 10/28/2008, 2:45 PM |
|
and in your Thankyou page put code like
echo CCGetSession("NewUserID","") ;
before your code so you also can check if itis correct
_________________
Gena |
 |
 |
rado
Posts: 221
|
| Posted: 10/28/2008, 3:00 PM |
|
I'm getting user_id that was just registered (which is good). Then the problem is probably in my Thankyou page. Here is the code of my Thankyou_events.php page:
<?php
//BindEvents Method @1-D40060DD
function BindEvents()
{
global $CCSEvents;
$CCSEvents["BeforeShow"] = "Page_BeforeShow";
}
//End BindEvents Method
//Page_BeforeShow @1-747506C2
function Page_BeforeShow(& $sender)
{
$Page_BeforeShow = true;
$Component = & $sender;
$Container = & CCGetParentContainer($sender);
global $Thankyou; //Compatibility
//End Page_BeforeShow
//DLookup @10-2D28009C
global $DBConnection_rr_db;
$Page = CCGetParentPage($sender);
$ccs_result = CCDLookUp(user_login, users, CCGetSession("NewUserID",""), $Page->Connections["Connection_rr_db"]);
$ccs_result = strval($ccs_result);
$Container->user_login->SetValue($ccs_result);
//End DLookup
//Close Page_BeforeShow @1-4BC230CD
return $Page_BeforeShow;
}
//End Close Page_BeforeShow
?>
Do you think that something is missing here?
Thanks, Rado
|
 |
 |
Gena
Posts: 591
|
| Posted: 10/28/2008, 3:08 PM |
|
put ' ' around ...user_login, users,... so like this
'user_login','users',
_________________
Gena |
 |
 |
Gena
Posts: 591
|
| Posted: 10/28/2008, 3:25 PM |
|
also, again, should it be user_id instead of user_login???
_________________
Gena |
 |
 |
|


|