ckroon
Posts: 869
|
Posted: 11/07/2006, 7:54 AM |
|
I have built a multi-page form for a parent admission database. The form spans 8 pages.
I copied the Multi-Step registration solution exactly. It works fine when I test it locally, but live, on the web, it doesn't transfer the record ID from the first page onto the second page, so the Next button does not show up.
This is the code that is on the form on page one, in the After Insert Event:
global $DBConnection1;
global $Redirect;
if(!CCGetFromGet("ID",0)) {
$LastID = CCDLookup("max(ID)","appmain","ID=".$DBConnection1->ToSQL(CCGetFromPost("ID",""),ccsText),$DBConnection1);
if (strpos($Redirect,"?") == false ) {
$Redirect = $Redirect."?ID=".$LastID;
} else if (substr($Redirect,-1) == "?" ) {
$Redirect = $Redirect."ID=".$LastID;
} else {
$Redirect = $Redirect."&ID=".$LastID;
}
}
The form on page 1 has a reutrn page of Page Two. The Next button on the first form is set to Insert.
On Page two, the form is set to return to page three and the Next button is set to Update.
Anyone have any idea what I am doing wrong.. the "it works locally but not on teh we" thing seems really weird to me.
ALso: On the web, when you go from page One to Page TWo, the URL says ID=. When I test it locally, the record number dsiplays in the URL.
Thanks!
_________________
Walter Kempees...you are dearly missed. |
|
|
WKempees
|
Posted: 11/07/2006, 9:40 AM |
|
The fact that it is not working must be in the CCDLookUp() not returning the
ID.
What is "appmain", it should be the name of the SQL Table, is it ?
echo the $LastID to see what it contains, while tampering with the
CCDLoopkUp().
echo 'lastid = '. $LastID
Also this snippet you use, should be in the AfterInsert of the first Form.
Another pitfall might be a difference in your local and remote Database,
such as Upper/Lowercase.
Check if the Inserted record of the First page is actually in the DB.
This because it works localy but not remote.
I'd put my money on somekind of DB problem.
Walter
|
|
|
ckroonn
|
Posted: 11/07/2006, 10:31 AM |
|
Thanks for the reply Walter.
The record IS inserted into the DB when you hit the Next button off of the first form page and the ID table name is the same (uppercase) in both local and remote databases.
I have no idea what you are talking about when you say "echo the LastID".. sorry :)
The sample in the Solution pack had this code:
//Retrieve the last inserted key if a new user is registered
//This method of retrieving the last inserted key is safe because the value of the user_login field has to be unique.
if(!CCGetFromGet("user_id",0)) {
$LastID = CCDLookup("max(user_id)","users","user_login=".$DBInternetDB->ToSQL(CCGetFromPost("user_login",""),ccsText),$DBInternetDB);
if (strpos($Redirect,"?") == false ) {
$Redirect = $Redirect."?user_id=".$LastID;
} else if (substr($Redirect,-1) == "?" ) {
$Redirect = $Redirect."user_id=".$LastID;
} else {
$Redirect = $Redirect."&user_id=".$LastID;
}
}
And I simply replaced the Connection name, the table name to 'appmain' and the user_id field to 'ID'.
Is it because the code was designed for use with a login?
You can see it here: http://www.cavatest.com/demo2/adminapp1.php
Thanks!
|
|
|
WKempees
|
Posted: 11/07/2006, 12:53 PM |
|
The sample is ok, your approach also.
Still, I suspect the CCDLookUp() is not returning a value.
It can have several causes.
Is the field ID in your table: appmain an autoincrement field ?
check your Gmail
|
|
|
WKempees
|
Posted: 11/07/2006, 1:05 PM |
|
IF: your ID field is an autoincrement field and of type INT
then substitute your block of code with this.
optionally if you want to keep your block for future reference COMMENT it by
putting /* on the line before "if (! " and */ on the line following the last
closing bracket.
Then copy the block before or after the commented block.
if (!CCGetFromGet("ID",0)) {
$LastID = CCDLookUp("last_insert_id()","","",$DBConnection1);
if (strpos($Redirect,"?") == false ) {
$Redirect = $Redirect."?ID=".$LastID;
} else if (substr($Redirect,-1) == "?" ) {
$Redirect = $Redirect."ID=".$LastID;
} else {
$Redirect = $Redirect."&ID=".$LastID;
}
}
If this still does not function than either the tablename is spelled wrong
or your ID is not autoincrement.
Walter
|
|
|
wkempees
Posts: 1679
|
Posted: 11/07/2006, 2:33 PM |
|
The solution:
The originaly used code, taken from MultiStepRegistration Example and adjusted, has
global $DBConnection1;
global $Redirect;
if(!CCGetFromGet("ID",0)) {
$LastID = CCDLookup("max(ID)","appmain","ID=".$DBConnection1->ToSQL(CCGetFromPost("ID",""),ccsText),$DBConnection1);
if (strpos($Redirect,"?") == false ) {
$Redirect = $Redirect."?ID=".$LastID;
} else if (substr($Redirect,-1) == "?" ) {
$Redirect = $Redirect."ID=".$LastID;
} else {
$Redirect = $Redirect."&ID=".$LastID;
}
}
For testing purposes we added:
echo "LastID is : " . $LastID ;
just before the if() construct.
This will ruin the application but will display the value of $LastID.
Using that it turned out, as I suspected, to be NULL always.
By changing " var $Debug = 0; " to " var $Debug = 1; "
in Common Files, db_mysql.php, The appilication will show all the SQL statements.
It reported:
SELECT max(ID) from appmain where ID=NULL;
That is an invalid SQL statement "ID=NULL" should be "ID is NULL".
removing the where part of the CCDLookUp, should be sufficient to make things work.
$LastID = CCDLookup("max(ID)","appmain","",ccsText),$DBConnection1);
And it did.
As the example clearly states this not the safest way to get the Last ID.
This is (optional) the safer way to go:
if (!CCGetFromGet("ID",0)) {
$LastID = CCDLookUp("last_insert_id()","","",$DBConnection1);
if (strpos($Redirect,"?") == false ) {
$Redirect = $Redirect."?ID=".$LastID;
} else if (substr($Redirect,-1) == "?" ) {
$Redirect = $Redirect."ID=".$LastID;
} else {
$Redirect = $Redirect."&ID=".$LastID;
}
}
Do not forget to remove the echo statement and reset " var $Debug ".
Walter
_________________
Origin: NL, T:GMT+1 (Forumtime +9)
CCS3/4.01.006 PhP, MySQL .Net/InMotion(Vista/XP, XAMPP)
if you liked this info PAYPAL me: http://donate.consultair.eu
|
|
|
|