CodeCharge Studio
search Register Login  

Web Reports

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

YesSoftware Forums -> CodeCharge Studio -> PHP

 Insert Record Retain New Value

Print topic Send  topic

Author Message
sboswell

Posts: 2
Posted: 03/26/2006, 3:20 PM

I am using a Record Form to insert a new record into the mySQL DB. Insert works fine. I would like to insert the record and pull the new record primary key value. New record has a Primary Key field name LeadID.

The goal is to add the record and move to an editable grid with the new Primary Key value added to the URL.

It would look something like this:

Click add button at the bottom of Maintenance1.php. That page inserts a new record into the database. Maintenance2.php needs to have the Primary Key field added to its URL. IE mywebsite.com/Maintenance2.php?LeadID=3.

Any help would be greatly appreciated. I have read many ways to pull a record but dont know how to pull one that is just being added.
View profile  Send private message
Ans

Posts: 53
Posted: 03/26/2006, 4:57 PM

http://examples.codecharge.com/ExamplePack/MasterDetail...Detail_desc.php

Try the above example. It uses a code to grab the latest added ID and place it into the URL. Then another set of code to place it in the hidden field.Pretty nifty!
View profile  Send private message
WKempees
Posted: 03/27/2006, 4:20 AM

and in addition to Ans,
Use the "search" in this forum, top menu.
Search for "last insert"will give you usefull discussions too.

Walter

"sboswell" <sboswell@forum.codecharge> schreef in bericht
news:5442721bf3f691@news.codecharge.com...
>I am using a Record Form to insert a new record into the mySQL DB. Insert
>works
> fine. I would like to insert the record and pull the new record primary
> key
> value. New record has a Primary Key field name LeadID.
>
> The goal is to add the record and move to an editable grid with the new
> Primary
> Key value added to the URL.
>
> It would look something like this:
>
> Click add button at the bottom of Maintenance1.php. That page inserts a
> new
> record into the database. Maintenance2.php needs to have the Primary Key
> field
> added to its URL. IE mywebsite.com/Maintenance2.php?LeadID=3.
>
> Any help would be greatly appreciated. I have read many ways to pull a
> record
> but dont know how to pull one that is just being added.
> ---------------------------------------
> Sent from YesSoftware forum
> http://forums.codecharge.com/
>

sboswell

Posts: 2
Posted: 03/27/2006, 4:45 AM

Thanks all so far. Big help. However, the example pack is in asp. I am not a coder and am having trouble converting ASP to PHP. Can anyone help? I started with the ASP code

Dim LastID

'Retrieve the last inserted key
LastID = CCDLookUp("max(emp_id)","employees","", DBIntranetDB)
'Append the last inserted key to the URL by modifying the 'Redirect' variable
redirect = FileName &"?"&CCAddParam(CCRemoveParam(Request.QueryString,"ccsForm"), "emp_id", LastID)

and attempted to modify this code to work with PHP

//Custom Code @50-2A29BDB7
// -------------------------
function LastID()
{
global $LastID
//Retrieve the last inserted key
$LastID = CCDLookUp("max(LeadID)","LeadTable","","$DBConnection1")
//Append the last inserted key to the URL by modifying the 'Redirect' variable
$redirect = $FileName &"?"&CCAddParam(CCRemoveParam(Request.QueryString,"ccsForm"), "LeadID", $LastID)
}
// -------------------------
//End Custom Code

What am I doing wrong???
View profile  Send private message
WKempees
Posted: 03/27/2006, 4:52 AM

Example pack being in ASP is no trouble whatsoever.
Open CCS
New project
Look at the tabs and select Solutions
Then choose example pack.
I might have skipped a step but ii is described several times in this forum.
Walter

Quote :
The example projects shouldn't be opened at all, just used as templates for
new
projects. Here are the intsructions:
http://docs.codecharge.com/studio3/html/ProgrammingTech...xamplePack.html
_________________
Peter R.
YesSoftware Forums Moderator
For product support please visit http://support.yessoftware.com
---------------------------------------
Sent from YesSoftware forum
http://forums.codecharge.com/





"sboswell" <sboswell@forum.codecharge> schreef in bericht
news:54427de5aa3203@news.codecharge.com...
> Thanks all so far. Big help. However, the example pack is in asp. I am not
> a
> coder and am having trouble converting ASP to PHP. Can anyone help? I
> started
> with the ASP code
>
> Dim LastID
>
> 'Retrieve the last inserted key
> LastID = CCDLookUp("max(emp_id)","employees","", DBIntranetDB)
> 'Append the last inserted key to the URL by modifying the 'Redirect'
> variable
> redirect = FileName
> &"?"&CCAddParam(CCRemoveParam(Request.QueryString,"ccsForm"), "emp_id",
> LastID)
>
>
> and attempted to modify this code to work with PHP
>
> //Custom Code @50-2A29BDB7
> // -------------------------
> function LastID()
> {
> global $LastID
> //Retrieve the last inserted key
> $LastID = CCDLookUp("max(LeadID)","LeadTable","","$DBConnection1")
> //Append the last inserted key to the URL by modifying the 'Redirect'
> variable
> $redirect = $FileName
> &"?"&CCAddParam(CCRemoveParam(Request.QueryString,"ccsForm"), "LeadID",
> $LastID)
> }
> // -------------------------
> //End Custom Code
>
> What am I doing wrong???
> ---------------------------------------
> Sent from YesSoftware forum
> http://forums.codecharge.com/
>

Ans

Posts: 53
Posted: 03/27/2006, 4:16 PM

You can open the example pack in CCS in php format.
View profile  Send private message
Mohamad Sibai
Posted: 04/08/2006, 4:24 AM

Gueys,
looking for the maximim ID is not the perfect solution, maybe after inserting the record and before getting the max id, somebody else may insert another record ... so I would prefer to add the lock/unlock sql commands before insertion and after selecting the maximum id.

Regards.
WKempees
Posted: 04/08/2006, 4:36 AM

@M,

Safe method in Php Using MySQL:

In the AfterExecuteInsert
$LastID = mysql_insert_id();
some code....

  
//cal_object_booking1_ds_AfterExecuteInsert @74-490A257D  
function cal_object_booking1_ds_AfterExecuteInsert(& $sender)  
{  
    $cal_object_booking1_ds_AfterExecuteInsert = true;  
    $Component = & $sender;  
    $Container = CCGetParentContainer($sender);  
    global $cal_object_booking1; //Compatibility  
//End cal_object_booking1_ds_AfterExecuteInsert  
  
//Custom Code @90-2A29BDB7  
// -------------------------  
    // Write your own code here.  
// -------------------------  
 $LastBookingID = mysql_insert_id();  
 Insert_Calendar($LastBookingID);  
  
//End Custom Code  
  
//Close cal_object_booking1_ds_AfterExecuteInsert @74-89D126C3  
    return $cal_object_booking1_ds_AfterExecuteInsert;  
}  
//End Close cal_object_booking1_ds_AfterExecuteInsert  
  


Mohamad Sibai
Posted: 04/10/2006, 12:42 AM

Cool function..
but this will use native insert ..
It would be a great pleasure if YesSoftware could provide this utility as a function after insert called "CCGetLastInsertedID()" forexampl...
I know that DB_SQL Class doesn't provid that but it could be modified to use your function (I mean YesSoftware can provide a patch with updated DB_SQL class and a new CCGetLastInsertedID function)..

Quote WKempees:
@M,

Safe method in Php Using MySQL:

In the AfterExecuteInsert
$LastID = mysql_insert_id();
some code....

  
//cal_object_booking1_ds_AfterExecuteInsert @74-490A257D  
function cal_object_booking1_ds_AfterExecuteInsert(& $sender)  
{  
    $cal_object_booking1_ds_AfterExecuteInsert = true;  
    $Component = & $sender;  
    $Container = CCGetParentContainer($sender);  
    global $cal_object_booking1; //Compatibility  
//End cal_object_booking1_ds_AfterExecuteInsert  
  
//Custom Code @90-2A29BDB7  
// -------------------------  
    // Write your own code here.  
// -------------------------  
 $LastBookingID = mysql_insert_id();  
 Insert_Calendar($LastBookingID);  
  
//End Custom Code  
  
//Close cal_object_booking1_ds_AfterExecuteInsert @74-89D126C3  
    return $cal_object_booking1_ds_AfterExecuteInsert;  
}  
//End Close cal_object_booking1_ds_AfterExecuteInsert  
  




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.

Web Database

Join thousands of Web developers who build Web applications with minimal coding.
CodeCharge.com

Home   |    Search   |    Members   |    Register   |    Login


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