Advertisement

07.20.2008 at 07:51PM PDT, ID: 23580806
[x]
Attachment Details

Getting confused with escaping characters

Asked by DJ_AM_Juicebox in PHP and Databases, PHP Scripting Language

Hi,

I need to write a PHP function to escape characters for an SQL statement. I think the characters I need to lookout for are:

    single quote      '
    double quote    "
    backslash          \

I know I can use something found on the net, I just want to give this a try first. I'm using a simple string replace method, but am getting confused on what to replace the found characters with. For example:

     Single Quote,   Find ("\'")  Replace with ("\\'");
     Double Quote, Find ("\"")  Replace with ("\\\"");
     Backslash,       Find("\\")   Replace with ("\\\\");

That works when I print them to screen - but I"m confused if the replace with strings I posted are the proper things for use with an actual SQL statement.

ThanksStart Free Trial
[+][-]07.20.2008 at 08:19PM PDT, ID: 22047867

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]07.20.2008 at 08:20PM PDT, ID: 22047872

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]07.20.2008 at 08:34PM PDT, ID: 22047906

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]07.21.2008 at 02:12AM PDT, ID: 22048935

View this solution now by starting your 7-day free trial. Setting up your free trial is quick, easy, and secure. We will return you to this solution, unlocked, when you're done.

 

About this solution

Zones: PHP and Databases, PHP Scripting Language
Sign Up Now!
Solution Provided By: GPFGSantos
Participating Experts: 2
Solution Grade: A
 
 
 
Loading Advertisement...
20080716-EE-VQP-32 / EE_QW_2_20070628