CodeCharge Studio
search Register Login  

Visual Web Reporting

Visually create Web Reports in PHP, ASP, .NET, Java, Perl and ColdFusion.
CodeCharge.com

YesSoftware Forums -> CodeCharge Studio -> PHP

 [RESOLVED] Add Parm To Href URL After Insert

Print topic Send  topic

Author Message
maxhugen

Posts: 272
Posted: 04/22/2008, 12:31 AM

I have a Clients page, where the user click a button "Add New Consultation".

This takes them to page Consultation_New, with a URL parm 'PID' (client id) which fills in the Client ID using the default value CCGetParam('PID',NULL).

The idea is for the user to enter the bare minimum for a Consultation, being the Client ID and the Consultation Date , and then save using the Submit button.

The Submit button's href points to page Consultation, passing along the URL parm 'PID' (which it does OK). However, I need to add a second URL parm, 'CID' (consultation_id), which has just been created.

I tried using the Form's AfterInsert event to try to add this second parm to the URL, but it's rubbish unfortunately:
global $CID;  
$CID = CCDLookUp("LAST_INSERT_ID()", "consultation", "LAST_INSERT_ID()", $DBEIP_MySQL);  
$qs = CCGetQueryString("Form", $RemoveParameters);  
CCAddParam($qs, "CID", $CID);

I need some help with where/how to do this correctly pls!
_________________
Max
www.gardenloco.com | www.eipdna.com | www.chrisarminson.com
View profile  Send private message
mamboBROWN


Posts: 1713
Posted: 04/22/2008, 7:55 PM

maxhugen
Can you give us some more information about what you mean by "it's rubbish" what value is being returned by the CCDLookup?
View profile  Send private message
maxhugen

Posts: 272
Posted: 04/22/2008, 8:18 PM

Sorry, that wasn't very useful, some frustration creeping in...

I don't know how to view the value of $CID. I tried "echo $CID;" but nothing displays.

What happens with the above code is I'm sent to a page with URL:

.../Consultation_New.php?PID=1898128231&ccsForm=consultation

So, its not going to the page specified (consultation) in the href at all. And I don't know what to make of the parm appended, "ccsForm=consultation". Incidentally, the page doesn't display anything at all.

I also tried commenting out the 3rd and 4th lines of the code, but it still sent me to the same URL address.

(oh, for a good php debugger...)
_________________
Max
www.gardenloco.com | www.eipdna.com | www.chrisarminson.com
View profile  Send private message
tonyk

Posts: 163
Posted: 04/24/2008, 3:59 PM

It sounds as if the application is quite secure. Might you be better of creating a session variable which is read by the target page. Nothing shows in the url so it should be harder to spoof. The target page resets the session variable after reading in the record.
Tony
View profile  Send private message
maxhugen

Posts: 272
Posted: 04/24/2008, 6:36 PM

Hi Tony

Worth a try. At least then I'd know if the CCDLookUp was working!
_________________
Max
www.gardenloco.com | www.eipdna.com | www.chrisarminson.com
View profile  Send private message
maxhugen

Posts: 272
Posted: 04/24/2008, 7:03 PM

Still having strange issues. I changed the Form's AfterInsert event to:
global $CID;  
$CID = CCDLookUp("LAST_INSERT_ID()", "consultation", "LAST_INSERT_ID()", $DBEIP_MySQL);  
CCSetSession("LastCID", $CID );
1. The page doesn't go to the Href specified in the Submit button
2. Nothing was set in the session
3. Strange parameter is added to this page's URL: ccsForm=consultation
4. This page came back blank.

Any thoughts please?
_________________
Max
www.gardenloco.com | www.eipdna.com | www.chrisarminson.com
View profile  Send private message
tonyk

Posts: 163
Posted: 04/24/2008, 8:13 PM

What you may find helpful is to look at the after insert event.
If you have little traffic and if each user has his/her user id embedded in the new document you could set up a short sql query to check for the max key corresponding to that user after the record has been inserted, this should be the key of the latest consultation record created by that user.

An alternative is to create a fresh random string in a field on the record and then find the key_id for that record, you can set the key recovered by either method as a session variable and it will be available in the next page.

$sql="SELECT MAX(primary_key) AS maxkey FROM table WHERE input_user_id=".CCGetUserID();
// this should be last record in for that user
$db=new clsDBConnection1;
$result=$db->query($sql);
if(!$result){
echo mysql_error()."<br>";
echo $sql;
}
while($db->nextrecord()){
$keytotransfer=$db->f("maxkey");
}
$db->close();
CCSetSession("keyout",$keytotransfer);
View profile  Send private message
maxhugen

Posts: 272
Posted: 04/24/2008, 8:49 PM

Quote tonyk:
What you may find helpful is to look at the after insert event.
I'm already using the Form AfterInsert event... am I missing something here?
_________________
Max
www.gardenloco.com | www.eipdna.com | www.chrisarminson.com
View profile  Send private message
tonyk

Posts: 163
Posted: 04/25/2008, 7:02 AM

You have to recover the id for the newly inserted record, it will not be in your form after you insert which is why you need to go discover and get it.
The method above does just that.
Tony
View profile  Send private message
tonyk

Posts: 163
Posted: 04/25/2008, 5:25 PM


Alternatively why not create a redirect, you can include the parameters directly in the query string you build
i.e.
global $Redirect;
$Redirect="Consultation_New.php?PID=".CCGetParam('PID',NULL)."&CID=".$CID;

Put this in the after_insert event. You have of course to recover the record id of the newly created consultation as stated previously.
Tony
View profile  Send private message
maxhugen

Posts: 272
Posted: 04/25/2008, 6:33 PM

Thanks Tony

I've tried the code you suggested, but I'm still having strange issues! As before:

1. The page doesn't go to the Href specified in the Submit button (ie 'Consultation')
2. Nothing was set in the session
3. Strange parameter is added to this page's URL: ccsForm=consultation
4. This page came back blank.

    $sql="SELECT MAX(ConsultationID) AS LastCID FROM Consultation WHERE ClientID=".$Component->$ClientID.GetValue();  
    $db=new clsDBEIP_MySQL;  
    $result=$db->query($sql);  
    if(!$result){  
        echo mysql_error()."<br>";  
        echo $sql;  
    }  
    while($db->nextrecord()){  
        $LastCID = $db->f("LastCID");  
    }  
    $db->close();  
  
    CCSetSession("LastCID",$LastCID);
Something seems to be going haywire in the Form AfterInsert event, but I don't know why.

I progressively commented out the code, until I found where it 'breaks'. It doesn't like the first line:
$sql="SELECT MAX(ConsultationID) AS LastCID FROM Consultation WHERE ClientID=".$Component->$ClientID.GetValue();

If I change this to $sql="SELECT MAX(ConsultationID) AS LastCID FROM Consultation WHERE ClientID=3"; it doesn't 'break'.

I had tried this with my earlier code too, and found that the CCDLookUp() caused problems.

I'm wondering if there is a bug in the Form AfterInsert event. I have already found a couple of other bugs in CCS, which YesSoftware supplied patches for.

Tony, have you used this event successfully?
_________________
Max
www.gardenloco.com | www.eipdna.com | www.chrisarminson.com
View profile  Send private message
tonyk

Posts: 163
Posted: 04/26/2008, 8:25 PM

Try $Component->GetValue()

or

$Container->$CientID->GetValue()

The former if you are using an event tied to the control, the latter if an event tied to the form.


BTW Should it be CientID or should it be ClientID ?

Are you missing an 'L' somewhere?

Otherwise the code looks OK to me,but I am only an enthusiast rather than an expert
:-)

What errors are being returned?

Tony
View profile  Send private message
maxhugen

Posts: 272
Posted: 04/27/2008, 4:24 PM

Hi Tony

Although you're right about the typo, it makes no difference, still the same issues.

Tried your alternate code, no difference.

I'll try YesSoftware Support.
_________________
Max
www.gardenloco.com | www.eipdna.com | www.chrisarminson.com
View profile  Send private message
maxhugen

Posts: 272
Posted: 04/30/2008, 5:14 AM

Helen from Yes Support pointed me to the Example Pack MultiStepRegistration example, which provided the answers.

My code is now:
    global $DBEIP_MySQL;  
    global $Redirect;  
    if (!CCGetFromGet("ConsultationID",0)) {  
        $LastCID = CCDLookUp("LAST_INSERT_ID()", "consultation", "", $DBEIP_MySQL);  
        if (strpos($Redirect,"?") == false ) {  
            $Redirect = $Redirect."?CID=".$LastCID;  
        } else if (substr($Redirect,-1) == "?" ) {  
            $Redirect = $Redirect."CID=".$LastCID;  
        } else {  
            $Redirect = $Redirect."&CID=".$LastCID;  
        }  
    }
I'm still puzzled as to why Tony's method didn't work. As it wouldn't continue past the first line:
$sql="SELECT MAX(ConsultationID) AS LastCID FROM Consultation WHERE ClientID=".$Component->$ClientID.GetValue();
... perhaps it should be something like:
$sql="SELECT MAX(ConsultationID) AS LastCID FROM Consultation WHERE ClientID=".CCGetFromGet("ClientID",0);
Anyway, its all working now.... on to the next challenge! 8-)
_________________
Max
www.gardenloco.com | www.eipdna.com | www.chrisarminson.com
View profile  Send private message
tonyk

Posts: 163
Posted: 05/01/2008, 6:31 AM

Maybe the typo stopped it!
Glad you got there in the end
Tony
View profile  Send private message

Add new topic Subscribe to topic   


These are Community Forums for users to exchange information.
If you would like to obtain technical product help please visit http://support.yessoftware.com.

PHP Reports

Visually create Web Reports in PHP, ASP, .NET, Java, Perl and ColdFusion.
CodeCharge.com

Home   |    Search   |    Members   |    Register   |    Login


Powered by UltraApps Forum created with CodeCharge Studio
Copyright © 2003-2004 by UltraApps.com  and YesSoftware, Inc.