SitePoint Sponsor

User Tag List

Results 1 to 5 of 5
  1. #1
    SitePoint Enthusiast
    Join Date
    Jun 2008
    Posts
    41
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Newby I am sure. How to display a varchar that has a double quote in it.

    I have a field product name that is a varchar 50. I use Addslashes when I store it to the db.

    Might look like: [12\" Lead Pipe] in the db.

    When I go to display it on the screen I run into trouble.

    If I do nothing I get 12\" Lead Pipe

    If I stripslashes() I get 12 on the screen.

    Not sure how to handle this.
    I know if I make the field a text field it will work. How do you handle special characters in a varchar field properly?


    TIA: Frank

  2. #2
    rajug.replace('Raju Gautam'); bronze trophy Raju Gautam's Avatar
    Join Date
    Oct 2006
    Location
    Kathmandu, Nepal
    Posts
    4,013
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I don't know what is the problem with you, but stripslashes() should work in varchar field as well. I doubt that you are displaying the value the text box. So double quote is giving the problem. Try:
    PHP Code:
    echo "<input type=\"text\" name=\"txt\" value=\"" htmlentities(stripslashes($rows['Titel'])) . "\" />"
    Mistakes are proof that you are trying.....
    ------------------------------------------------------------------------
    PSD to HTML - SlicingArt.com | Personal Blog | ZCE - PHP 5

  3. #3
    reads the ********* Crier silver trophybronze trophy longneck's Avatar
    Join Date
    Feb 2004
    Location
    Tampa, FL (US)
    Posts
    9,854
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    if you look at the row in phpmyadmin, do you also see the slash? if so, you probably have magic quotes on. magic quotes are evil.
    Check out our new Industry News forum!
    Keep up-to-date with the latest SP news in the Community Crier

    I edit the SitePoint Podcast

  4. #4
    SitePoint Wizard
    Join Date
    Mar 2008
    Posts
    1,149
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Don't use addslashes(). Different characters are different control characters to different DBMSes. For the MySQL extension, it's mysql_real_escape_string().

    When you pull it back out, it should come out in its original form (before escaping the string).

  5. #5
    SitePoint Wizard bronze trophy
    Join Date
    Jul 2008
    Posts
    5,757
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by Phrank View Post

    If I do nothing I get 12\" Lead Pipe

    If I stripslashes() I get 12 on the screen.
    In html, browsers render an image of the webpage for you. This means you don't get to see the actual data. right click > view html source. The data is there. You're mistake is probably invalid html, and my guess is this

    Code:
    <tag attribute="12" Lead Pipe">
    So, of course you would expect the browser to choke and not know what to do. It doesn't know which quote is the ending delimiter.

    see the htmlspecialchars() function.


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •