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

 sting variables concatenated with 'single quotes'

Print topic Send  topic

Author Message
andy


Posts: 183
Posted: 01/03/2012, 6:01 AM

THE CURSE OF THE SINGLE QUOTES... Aghhhhhhhhhhhhhhhh

This shouldn't be difficult but...

I am updating an existing record after inserting a new record and so am using the AfterInsert event (the form automatically inserts to one table, the code updates another table).

I'm grabbing the form field values as follows:
$VOrganisation_Name = $db->ToSQL($register->Organisation_Name->GetValue(),ccsText);  
$VFullName = $db->ToSQL($register->FullName->GetValue(),ccsText);


I want to concatenate these two strings and add some additional text to use in my update query... Should be simple huh?
Unfortunately, single quote marks are bracing the output of my variables...

Here's what I have tried:
$Vorgfullname = $db->ToSQL($VLastName." of ".$VOrganisation_Name,ccsText);  
  
// This returns:   'my-lastname-value' of 'my-organisation-value'  
It should return: my-lastname-value of my-organisation-value

If I just concatenate with straightforward php like this, the single quotes:
$Vorgfullname = "$VLastName of $VOrganisation_Name";  
$Vorgfullname = "'".$VLastName." of ".$VOrganisation_Name."'";  
$Vorgfullname = "'".$VLastName.' of '.$VOrganisation_Name."'";  
  
//All return:   nothing (fails)  


It doesn't make any difference whether or not I declare my variables as global
e.g. global $Vorgfullname;

Somebody please put me out of my misery... Thanks
:-|
_________________
Andy

RAD tools for rich UI controls:
http://www.koolphptools.com
View profile  Send private message
datadoit
Posted: 01/03/2012, 7:53 AM

The $db->ToSQL() or CCToSQL() function is what is encasing the single
quotes, as they should. They are the decider functions as to whether or
not single quotes are needed for the SQL statement, or whether a NULL
value is needed.

So if you're just assigning values to variables, then you don't need the
quotes at this point. Only use the CCToSQL() function when building an
SQL statement.

Notice how I reference CCToSQL(), and not $db->ToSQL(). No active
connection needed for CCToSQL(). Can be used at any time. Ex:
Building an SQL statement before actually creating the SQL connection
object.
andy


Posts: 183
Posted: 01/03/2012, 11:42 AM

Thanks datadoit

You put me on the right track and I learned something new about CCToSQL().

Solution was as simple as it should have been in the first place.
For anyone else, grappling with the quotes here was the solution:
  
//Get the field values here  
$VOrganisation_Name = $register->Organisation_Name->GetValue();  
$VFullName = $register->FullName->GetValue();  
$Vorgfullname = $VFullName." (".$VOrganisation_Name.")";  // returns: fullname (organisationname)  
  
//Use CCToSQL in the SQL query only   
$sqlupdate = "UPDATE organisation SET DisplayName = ".CCToSQL($Vorgfullname,ccsText)." WHERE org_id=$Vorg_id";

One question, datadoit,
Presumably you can use all the datatypes with CCToSQL e.g. ccsDate, ccsBoolean, ccsInteger, ccsFloat, ccsText, ccsMemo.
If you don't use it with integer values, php seems to be a little more forgiving. Is it good practice to use it around integers too?
_________________
Andy

RAD tools for rich UI controls:
http://www.koolphptools.com
View profile  Send private message
datadoit
Posted: 01/03/2012, 3:13 PM

Yes, as it will handle NULL values.
andy


Posts: 183
Posted: 01/04/2012, 4:33 AM

Thanks datadoit.
Funny CCToSQL is not documented.

I have reformatted all my custom code accordingly.
_________________
Andy

RAD tools for rich UI controls:
http://www.koolphptools.com
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.

Internet Database

Visually create Web enabled database applications in minutes.
CodeCharge.com

Home   |    Search   |    Members   |    Register   |    Login


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