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

 Custom Code - SQL insert

Print topic Send  topic

Author Message
kbwill

Posts: 20
Posted: 03/27/2009, 7:36 AM

goal: insert a users job number into several tables at the moment a new job is created.

I have tried the Custom Insert in the properties window for table and SQL. Neither worked.
I have tried this code shown below as "Custom Code" to work but only tbl_1 actually gets the jobnbr, none of the other tables receive the number :
  
function jobnbr_inserts(& $sender) {    
$sqla = "INSERT INTO tbl_1(jobnbr) VALUES($jobnbr)";   
$db->query($sqla);   
$sqlb = "INSERT INTO tbl_2(jobnbr) VALUES($jobnbr)";   
$db->query($sqlb);    
$sqlc = "INSERT INTO tbl_3(jobnbr) VALUES($jobnbr)";   
$db->query($sqlc);   
$sqld = "INSERT INTO tbl_4(jobnbr) VALUES($jobnbr)";   
$db->query($sqld);    
$sqle = "INSERT INTO tbl_5(jobnbr) VALUES($jobnbr)";   
$db->query($sqle);   
}  

I tested this in a php page I constructed and it works fine.
I would rather get it to work inside CCS (3.2) than make an include page.
What am I missing on the above code?
_________________
Learning CentOS, CCS3.2,
some assembly may be required.
View profile  Send private message
mrachow


Posts: 509
Posted: 04/04/2009, 12:42 AM

My first guess was a missing commit but it shouldn't.

So maybe
$db->Error();
will show you something?
_________________
Best regards,
Michael
View profile  Send private message
melvyn


Posts: 333
Posted: 04/04/2009, 8:48 AM

OK. Understood.
Your issue came because you're executing an SQL statement that doesn't exist.
This is your code. Where are you defining the SQL to follow? Remember you're inside a function.
    
function jobnbr_inserts(& $sender) {      
$sqla = "INSERT INTO tbl_1(jobnbr) VALUES($jobnbr)";     
$db->query($sqla);     
}  
You're using $db wich isn't defined, which doesn't "exist". You need to always call your connection when you're on custom code.

To work try this:
    
function jobnbr_inserts(& $sender) {      
$db = new clsDB<your_db_connection>  
$sqla = "INSERT INTO tbl_1(jobnbr) VALUES($jobnbr)";     
$db->query($sqla);     
}  


Also you can call it in this way:
    
function jobnbr_inserts(& $sender) {      
global <your_db_connection>  
$sqla = "INSERT INTO tbl_1(jobnbr) VALUES($jobnbr)";     
$db->query($sqla);     
}  

Happy coding

Melvyn

_________________
Melvyn Perez
Puro Codigo
http://purocodigo.com
View profile  Send private message
gor

Posts: 6
Posted: 04/06/2009, 2:14 PM

You try this:
global $DB<name>; //if you use pconnect

$SQL = "INSERT INTO db
VALUES(" . $db<name>->ToSQL($value, ccsText) . ")";

$db<name>->query($SQL) or $db->halt(mysql_error());
_________________
Gor
View profile  Send private message
kbwill

Posts: 20
Posted: 04/07/2009, 7:55 AM

Quote melvyn:
OK. Understood.
Your issue came because you're executing an SQL statement that doesn't exist.
This is your code. Where are you defining the SQL to follow? Remember you're inside a function.
    
function jobnbr_inserts(& $sender) {      
$sqla = "INSERT INTO tbl_1(jobnbr) VALUES($jobnbr)";     
$db->query($sqla);     
}  
You're using $db wich isn't defined, which doesn't "exist". You need to always call your connection when you're on custom code.

To work try this:
    
function jobnbr_inserts(& $sender) {      
$db = new clsDB<your_db_connection>  
$sqla = "INSERT INTO tbl_1(jobnbr) VALUES($jobnbr)";     
$db->query($sqla);     
}  


Also you can call it in this way:
    
function jobnbr_inserts(& $sender) {      
global <your_db_connection>  
$sqla = "INSERT INTO tbl_1(jobnbr) VALUES($jobnbr)";     
$db->query($sqla);     
}  

Happy coding

Melvyn

Thanks Melvin,
I use the global $DBConnection which is called before the function. Either way tbl_1 is still the only one which receives the jobnbr.
Sincerely,
kbwill
_________________
Learning CentOS, CCS3.2,
some assembly may be required.
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.