Trouble with inserting a string containing a single quote

Using php with Oracle
If I do the following two lines before sending my $Query string through the parse function
$name = "Dominick's";
$Query = "INSERT INTO customers (name) values ('$name')";
it gives me the following error:
Warning: Ora_Parse failed (ORA-00917: missing comma -- while processing OCI function OPARSE)
If I try and force the single quote to be surrounded by double quotes and therefore not be confused:
$name = "Dominick's";
Query = "INSERT INTO customers (name) values (\"$name\")";
Trying that yields the following error:
Warning: Ora_Parse failed (ORA-01741: illegal zero-length identifier -- while processing OCI function OPARSE)
Help
Jeff

If it is possible (and here it is) you should use str_replace instead of ereg_replaceThanks for the reminder about str_replace().
$Query = "INSERT INTO customers (name) values ('".addSlashes($name)."')";This gives an invalid Oracle SQL statement, which will generally fail with
  ORA-01756: quoted string not properly terminatedFor Oracle, single quotes must be doubled, not escaped with backslash.
Of the solutions to insert the data, I'd prefer using bind variables
since no escaping or quote doubling is needed.
-- CJ

Similar Messages

  • How to insert a string containing a single quote to the msql database? help

    how can i insert a string which contains a single quote in to database... anyone help
    Message was edited by:
    sijo_james

    Absolutely, Positively use a PreparedStatement. Do not use sqlEscape() function unless you have some overriding need (and I don't know what that could possibly be).
    There are 1000's of posts on the positive aspects of using a PreparedStatement rather than using a Statement. The two primary positive attributes of using a PreparedStatement are automatic escaping of Strings and a stronger security model for your application.

  • I have been having trouble with inserting pages in a document in indesign

    having trouble with inserting pages in a document in indesign

    You're going to give us more information for us to help you.
    What operating system? What version of InDesign? What happens when you insert a page (and how are you choosing to insert a page)? Does it happen with just one file, or does also happen on a clean new file?

  • SSRS Report Returning Double Quote string from a Single Quote String

    Hi, I'm getting weird thing in resultset from SSRS report when executed. When I pass parameter to a report, which passes String that has single quote value to a split function , it returns rows with double quote. 
    For example  following string:
    'N gage, Wash 'n Curl,Murray's, Don't-B-Bald
    Returns: 
    ''N gage, Wash ''n Curl,Murray''s, Don''t-B-Bald
    through SSRS report.
    Here is the split function Im using in a report.
    CREATE Function [dbo].[fnSplit] (
    @List varchar(8000), 
    @Delimiter char(1)
    Returns @Temp1 Table (
    ItemId int Identity(1, 1) NOT NULL PRIMARY KEY , 
    Item varchar(8000) NULL 
    As 
    Begin 
    Declare @item varchar(4000), 
    @iPos int 
    Set @Delimiter = ISNULL(@Delimiter, ';' ) 
    Set @List = RTrim(LTrim(@List)) 
    -- check for final delimiter 
    If Right( @List, 1 ) <> @Delimiter -- append final delimiter 
    Select @List = @List + @Delimiter -- get position of first element 
    Select @iPos = Charindex( @Delimiter, @List, 1 ) 
    While @iPos > 0 
    Begin 
    -- get item 
    Select @item = LTrim( RTrim( Substring( @List, 1, @iPos -1 ) ) ) 
    If @@ERROR <> 0 Break -- remove item form list 
    Select @List = Substring( @List, @iPos + 1, Len(@List) - @iPos + 1 ) 
    If @@ERROR <> 0 Break -- insert item 
    Insert @Temp1 Values( @item ) If @@ERROR <> 0 Break 
    -- get position pf next item 
    Select @iPos = Charindex( @Delimiter, @List, 1 ) 
    If @@ERROR <> 0 Break 
    End 
    Return 
    End
    FYI: I'm getting @List value from a table and passing it as a string to split function. 
    Any help would be appreciated!
    ZK

    Another user from TSQL forum posted this code which is returning the same resultset but when I execute both codes in SQL server it works and return single quote as expected.
    https://social.msdn.microsoft.com/Forums/sqlserver/en-US/8d5c96f5-c498-4f43-b2fb-284b0e83b205/passing-string-which-has-single-quote-rowvalue-to-a-function-returns-double-quoate?forum=transactsql
    CREATE FUNCTION dbo.splitter(@string VARCHAR(MAX), @delim CHAR(1))
    RETURNS @result TABLE (id INT IDENTITY, value VARCHAR(MAX))
    AS
    BEGIN
    WHILE CHARINDEX(@delim,@string) > 0
    BEGIN
    INSERT INTO @result (value) VALUES (LEFT(@string,CHARINDEX(@delim,@string)-1))
    SET @string = RIGHT(@string,LEN(@string)-CHARINDEX(@delim,@string))
    END
    INSERT INTO @result (value) VALUES (@string)
    RETURN
    END
    GO
    ZK

  • URGENT  update a table with a text that has a single quote in it

    Hello, I am trying to update a table with a text that has a single quote in it. I believe I need to use two singles quotes but I am not sure how.
    For example:
    UPDATE TEST
    SET DESCRLONG='Aux fins d'exportations'
    WHERE etc...
    Should I put 2 singles quotes before the quote in the text?
    UPDATE TEST
    SET DESCRLONG='Aux fins d'''exportations'
    WHERE etc...
    Thank you very much :)

    The best way depends on the version of Oracle.
    But, the quick and universal answer is to use two single quotes
    SQL> connect test/test
    Connected.
    SQL> create table test (descrlong varchar2(128));
    Table created.
    SQL> insert into test values ('This is a string with a '' single quote');
    1 row created.
    SQL> select * from test;
    DESCRLONG
    This is a string with a ' single quote
    SQL> update test set descrlong='Aux fins d''exportations'
      2  where descrlong like 'T%';
    1 row updated.
    SQL> select * from test;
    DESCRLONG
    Aux fins d'exportations
    SQL>                                             

  • Passing String Which Has Single Quote Row/Value to a Function Returns Double Quoate

    Hi, I'm getting weird thing in resultset. When I pass String which has single quote value in it to a split function , it returns rows with double quote. 
    For example  following string:
    'N gage, Wash 'n Curl,Murray's, Don't-B-Bald
    Returns:
    ''N gage, Wash ''n Curl,Murray''s, Don''t-B-Bald
    Here is the split function:
    CREATE Function [dbo].[fnSplit] (
    @List varchar(8000), 
    @Delimiter char(1)
    Returns @Temp1 Table (
    ItemId int Identity(1, 1) NOT NULL PRIMARY KEY , 
    Item varchar(8000) NULL 
    As 
    Begin 
    Declare @item varchar(4000), 
    @iPos int 
    Set @Delimiter = ISNULL(@Delimiter, ';' ) 
    Set @List = RTrim(LTrim(@List)) 
    -- check for final delimiter 
    If Right( @List, 1 ) <> @Delimiter -- append final delimiter 
    Select @List = @List + @Delimiter -- get position of first element 
    Select @iPos = Charindex( @Delimiter, @List, 1 ) 
    While @iPos > 0 
    Begin 
    -- get item 
    Select @item = LTrim( RTrim( Substring( @List, 1, @iPos -1 ) ) ) 
    If @@ERROR <> 0 Break -- remove item form list 
    Select @List = Substring( @List, @iPos + 1, Len(@List) - @iPos + 1 ) 
    If @@ERROR <> 0 Break -- insert item 
    Insert @Temp1 Values( @item ) If @@ERROR <> 0 Break 
    -- get position pf next item 
    Select @iPos = Charindex( @Delimiter, @List, 1 ) 
    If @@ERROR <> 0 Break 
    End 
    Return 
    End
    FYI: I'm getting @List value from a table and passing it as a string to split function.
    Any help would be appreciated!
    ZK

    fixed the issue by using Replace function like
    Replace(value,'''''','''')
    Big Thanks Patrick Hurst!!!!! :)
    Though I came to another issue which I posted here:
    https://social.msdn.microsoft.com/Forums/sqlserver/en-US/a26469cc-f7f7-4fb1-ac1b-b3e9769c6f3c/split-function-unable-to-parse-string-correctly?forum=transactsql
    ZK

  • How to copy item value that contain a single quote(')?

    Hi,
    I have one "Copy" button in a APEX form. When user clicks it, it simply copy the item's values from the form to a new form by using APEX provided function behind the button- "Set these item values with these values". It is simple and works fine in normal cases. However, see, we have a text field called "Product Details", user types in for example "Oracle's new vision". When I click COPY button, APEX try to copy the text in "Product Details" field from this form to a new form but it returns error because of that single quote. Is there any way I can do something to replace that single quote with two single quote like we usually do in PL/SQL in the place "Set these item values with these values" of APEX button? I tried REPLACE(#P66_PRODUCT_DETAILS#., '''', '''''') but not work. I saw someone in the forum meantioned that to use something like "/#P66_PRODUCT_DETAILS#/" to get around. Any one with success?

    Thanks. I think it should work this way. However, our form has about 20 ~30 text fields, I have to create 20~30 hiddle fields to handle the problem because I never know which field could contain a single quote. Ideally, a new version of APEX should have the functionality to deal with the problem when using "set values with those values" method. At least, it should provide some kind of interaction for user to get away from single quote or comma or column etc.
    What I did is to get out of APEX native function and to create a new records in background by PL/SQL using record id that passed in from APEX form. It works perfectly. Although, user can only edit the record after it is created, not as user friendly as "Copy first-look at it-edit it-then create it" I originally planed.
    Thanks for your help,

  • Reading String within the single quotes

    Hi All,
    Can you please let me know, how to read a String within the sinle quote in line.
    I have to read a report into internal table and again from that I need to read a string within the single quote. Please help me in this.
    Thanks in Advance,
    Raghu

    I have the following code:
    REPORT  test.
    DATA:  v_test(05) TYPE c.
    v_test = ‘TTT’.
    I am getting this errror:
    Field “TTT” is unknown.  It is neither kin on e of the specified tables nor defined by a “DATA” statement.
    For some reason, my single quote is not being recognized from my keyboard.  I noticed that my emotion icons are not being displayed either (example:  I type and i do NOT get the smiley face on my end).
    Is there a button that I pressed that caused that?

  • String value changes single quote ' to double quote "

    I am creating a list with different bill codes within single
    quotes as follows
    <cfset corlist = " '1100 ','1200 ','1300 ','1700 ','1800
    ','1950 ','7001 ' ">
    when I do an output
    for
    <cfoutput>AND idbillcode IN ( #corlist
    #)</cfoutput>
    I get the values as follows
    AND idbillcode IN ( '1100 ','1200 ','1300 ','1700 ','1800
    ','1950 ','7001 ')
    However when I put the same string within a cfquery the
    single quotes get replaced by double quotes as follows
    AND idbillcode IN ( ''1100 '',''1200 '',''1300 '',''1700
    '',''1800 '',''1950 '',''7001 '') which throws an error.
    Anybody has any clues.
    Thanks.

    However when I put the same string within a cfquery the
    single quotes
    get replaced by double quotes as follows
    AND idbillcode IN ( ''1100 '',''1200 '',''1300 '',''1700
    '',''1800
    '',''1950
    '',''7001 '') which throws an error.
    Anybody has any clues.
    That is ColdFusion escaping the single quotes, by doubling
    them so that
    you can search for strings such as "singhpk's code does not
    work".
    (Note the single quote/apostrophe that would normally break
    this string
    if it was not escaped.
    To tell CF not to do this, one uses the
    preserveSingleQuotes() function.
    The documentation has all the details.

  • String comparison having single quote

    hi
    i m comparing a string which already have a single quote like this
    var_name=khurram' shehzad
    select * from table where name=' var_name ';
    plz help me how to do it bcoz its creating probelm
    thanks and regards,

    Hi,
    I hope the below example will help you.
    SQL>SELECT 'abc''' FROM DUAL WHERE 'abc''' = 'abc''';
    'ABC
    abc'
    1 row selected.
    SQL>
    Regards

  • Rest query with filter sub-string (contains, not eq)

    Hi,
    how can I do a REST-query with a filter for a string-column which is only a sub-string? I only found EQ, for example $filter=(name EQ 'tom') which compares the whole string.
    But I would like to query records, where a string-column CONTAINS a specific sub-string.
    Thx, Tom

    Hi Tom,
    Do you use it on azure Data Market place? Did you try to add "*" on your query string, like this
    post.
    Also, you could try this tool from this
    thread. Also, for this issue, I suggest you could post it on
    SQL forum for better support.
    If I misunderstood, please let me know.
    Regards,
    Will
    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click
    HERE to participate the survey.

  • Reinstalling Windows having trouble with insert media files.......

    HP Pavilion Sleekbook 14-b014tx Serial Number: [Personal Information Removed] Product Number: C7E03PA
    This laptop have last for more than 1year and I just felt that my device isnt running smooth so Ive decided to reinstall the windows/windows 8 single language 64bit , I cant perform the request it always notifies me "
    Insert Media Some files are missing. Your windows installation or recovery medial will provide these files"
    Anyone can help me , provide appropriate methods PLEASE HELP!!!!!

    HI @TechJohn ,
    Welcome to the HP Forums!
    It is a terrific place to find answers.
    For you to have the best experience in the HP forum I would like to direct your attention to the HP Forums Guide Learn How to Post and More
    I grasp that you decided to reinstall Windows 8 single language 64 bit but you get the error that it can't performs the request and asks you to insert media disk.
    How are you doing the reinstallation from a Windows disk or from Recovery disks.
    Here are links to assist you with doing a recovery back to factory.
    HP PCs - Performing an HP System Recovery (Windows 8)
    HP PCs - Troubleshooting HP System Recovery Problems (Windows 8)
    You will see an option to backup your personal files during this process. If you have not done one recently now is the perfect opportunity.
    HP PCs - Restoring Files that were Backed Up Using HP Recovery Manager (Windows 8)
    You can contact HP support at any time for assistance.
    Please call our technical support at 800 474 6836. If you live outside the US/Canada Region, please click the link below to get a support number for your region.
    World Wide Phone Support
    Best of Luck and have a terrific weekend!
    Sparkles1
    I work on behalf of HP
    Please click “Accept as Solution ” if you feel my post solved your issue, it will help others find the solution.
    Click the “Kudos, Thumbs Up" on the bottom right to say “Thanks” for helping!

  • Trouble with auto size text in a single line form field

    Hi.  I'm having an issue with filling out a form in Adobe Reader on my iPad.  The text field is single line.  The font is set to "auto" so that the line of text will not exceed a certain width.  When filling out this form on my laptop using Adobe Reader, it works fine.  As I type additional text, once the field is filled, it shrinks the text font size.  On my iPad, however, it won't let me type any more text in the field once I reach the end.  Does Adobe Reader for iPad not support the "auto" font size in form fields?  And I did check that my version of Adobe Reader is up to date on my iPad, so I do have the latest version.
    Thanks in advance for your help,
    Ashley

    Actually, nevermind.  It must be something wrong with the file.  I tried opening another file and auto resize worked perfectly on it.  Weird though that it works on one file and not another.
    Thanks!
    Ashley

  • Trouble with inserting pages in Adobe 9 Standard

    "Insert Pages" function was not available when trying to insert pages: from file:  is greyed out and the pdf's were created in Adobe 8 standard, did try the combine function using the merge function but the signatures were lost and it did state that it was better to do a portfolio but when doing the portfolio you are unable to select the display meaning how to look at the portfolio which is not good, because basically the insert pages function allows you to look at all pdf's together in a straight vertical line and the portfolio function you have to click one pdf at a time to really view the pdf even though they all show in the portfolio and they are displayed horizontal.
    I would think that Adobe 9 standard is compatible with pdf's created in Adobe 8 standard there has to be a work around to insert pages and have the option to put them before or after the pdf's that are already there.
    I am hoping someone can give some insight on this issue with Adobe 9 standard.

    You're going to give us more information for us to help you.
    What operating system? What version of InDesign? What happens when you insert a page (and how are you choosing to insert a page)? Does it happen with just one file, or does also happen on a clean new file?

  • Trouble with inserting a page

    Pages '09 v. 4.0.3
    While trying to insert a page in a Pages (Page Layout) document, using the "Insert" toolbar, I can get a blank page to insert, but the other templates merely flash the "inserting page" progression bar very quickly, but no page is inserted. Any ideas?
    Many thanks in advance!

    Do you mean you are using Insert > Pages > blank or text?
    If you look at the bottom of the page window you can read how many pages you have. That number doesn't change?
    Do you have thumbnails showing? You should see if you got a new page there. If you have chosen a page you already have you will get a new exactly the same page and for your eyes it will appear as you didn't get a new page.

Maybe you are looking for