CodeCharge Studio
search Register Login  

Visual PHP Web Development

Visually Create Internationalized Web Applications, Web Reports, Calendars, and more.
CodeCharge.com

YesSoftware Forums -> CodeCharge Studio -> General/Other

 HELP!!!! [Solved]

Print topic Send  topic

Author Message
ab5ni


Posts: 177
Posted: 08/26/2010, 12:14 PM

That's what I was figuring, datadoit, but wasn't absolutely positive things worked that way. No matter. It still doesn't work :(. Have a grid, click on addnew, first pop-up (a maint/record window generated by CCS) pops up, add all info for the record, and then click on a checkbox that pops up another maint/record window that adds a record and tries to send the primary key back to the first popup via the following code called in the After Insert Event:

  
global $last_insert_id;  
$SQL = "SELECT last_insert_id() as lid";  
$db->query($SQL);  
  
if($db->next_record()) {  
  $lid = $db->f("lid");  
  CCSetSession($last_insert_id,$lid);  
}  

After this code is executed and the window is closed, I try to pick up the session value via CCGetSession($last_insert_id) in the Before Insert event and assign the value returned to a hidden form value associated with the record. When I hit add to insert the new record, which hopefully contains the foreign key picked up via $last_insert_id, CCS comes back as says "rental_id can not be null" and doesn't add the new record. This is a correct statement, because this is a foreign key associated with the new record I'm trying to insert and can't be null. The record is not inserted, and MySQL doesn't allow the foreign key to be null.

Anywho, this has been driving me nuts for the last few days. As far as I can tell, it should work, but for some unknown reason to me, it doesn't. HELP!!! :(
_________________
Randall Jouett
Amateur Radio: AB5NI
I eat spaghetti code out of a bit-bucket while sitting at a hash table! And yes, I paid for the meal in cache!


View profile  Send private message
roeya


Posts: 181
Posted: 08/27/2010, 12:04 AM

What is the value of $last_insert_id

most likely it is either not initialized or have different values in you main page and the popup

why not use a trigger (MySQL has triggers ?) that automatically insert the new record in you main table ?


_________________
http://www.infoneto.com/
View profile  Send private message
Gena

Posts: 591
Posted: 08/28/2010, 7:30 AM

Your SQL code is wrong. It should be like this

    
$db = new clsDBxxxxDB();    
$SQL = "INSERT INTO store_orders " .    
[skip]    
$db->query($SQL);      
    
$SQL = "SELECT LAST_INSERT_ID() FROM store_orders";    
$db->query($SQL);    
if ($db->next_record())  {    
     $last_order_id = $db->f(0);    
}    
   

_________________
Gena
View profile  Send private message
ab5ni


Posts: 177
Posted: 08/30/2010, 3:56 PM

Well, Gena's code worked. The thing that really, really ticked me off about this situation is that every single piece of documentation I read mentioned nothing about using FROM in last_insert_id(). It makes total sense to use it, but every piece of example code I ran across used "SELECT LAST_INSERT_ID()" by itself or "SELECT LAST_INSERT_ID() as whatever".

It's also important to note that $db->f("whatever") should work in CCS, even if there is only one field to retrieve, yet, for some strange reason, it doesn't work for me. "$last_order_id = $db->f(0);" does work here, however. Go figure!

Anywho, tyvm for the fix, Gena!

_________________
Randall Jouett
Amateur Radio: AB5NI
I eat spaghetti code out of a bit-bucket while sitting at a hash table! And yes, I paid for the meal in cache!


View profile  Send private message
mamboBROWN


Posts: 1713
Posted: 08/31/2010, 7:35 PM

ab5ni,
Could you please add [RESOLVED] or [SOLVED] in the thread title. Thanks.
View profile  Send private message
ab5ni


Posts: 177
Posted: 09/01/2010, 3:12 PM

Surely....
_________________
Randall Jouett
Amateur Radio: AB5NI
I eat spaghetti code out of a bit-bucket while sitting at a hash table! And yes, I paid for the meal in cache!


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.

MS Access to Web

Convert MS Access to Web.
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.