1. Advertising
    y u no do it?

    Advertising (learn more)

    Advertise virtually anything here, with CPM banner ads, CPM email ads and CPC contextual links. You can target relevant areas of the site and show ads based on geographical location of the user if you wish.

    Starts at just $1 per CPM or $0.10 per CPC.

Slashes Problem

Discussion in 'PHP' started by greatlogix, Apr 23, 2008.

  1. #1
    When A customer enters " ' " (apostrophe) in their name PHP adds it like this Laura L\\\'Herault . Note 3 slashes. When I use stripslashes PHP removes only 2 slashes and output is Laura L\'Herault

    What to do to fix this problem.

    Thanks in advance.
    GreatLogix
     
    greatlogix, Apr 23, 2008 IP
    Barti1987 likes this.
  2. CreativeClans

    CreativeClans Peon

    Messages:
    128
    Likes Received:
    4
    Best Answers:
    0
    Trophy Points:
    0
    #2
    So the user writes Laura l'Herault in the form.
    Your script receives it through $_POST or $_GET and when you echo that value it shows Laura L\\\'Herault? With three slashes?
    Are you sure you didn't do any validation that might have added two slashes?
     
    CreativeClans, Apr 23, 2008 IP
    greatlogix likes this.
  3. greatlogix

    greatlogix Active Member

    Messages:
    664
    Likes Received:
    13
    Best Answers:
    1
    Trophy Points:
    85
    #3
    Yes original name is Laura L'Herault. I am using POST. No addslashes. I am saving data in MySQL DB. In data base its in this format Laura L\\\'Herault

    and on reports page after stripslashes its Laura L\'Herault
     
    greatlogix, Apr 23, 2008 IP
  4. Barti1987

    Barti1987 Well-Known Member

    Messages:
    2,703
    Likes Received:
    115
    Best Answers:
    0
    Trophy Points:
    185
    #4
    Nope it can't happen unless you are addslashing, if so, don't do (your server must be setup to add them automatically).

    What is actually happening is that you are submitting the form more than 1 time, each time, it'll add 1 slash you do and the one is done automatically.

    When you post the text on the form input, use strip-slashes before displaying it, it should fix it (new, not add-ons, which must be done manually).

    If else, post your code here (or pm) and I'll fix it for you.

    Peace,
     
    Barti1987, Apr 23, 2008 IP
    greatlogix likes this.
  5. crazyryan

    crazyryan Well-Known Member

    Messages:
    3,087
    Likes Received:
    165
    Best Answers:
    0
    Trophy Points:
    175
    #5
    Are you using mysql_real_escape_string when you enter it into the database? I think I had the same problem as you and it was because of mysql_real_escape_string.
     
    crazyryan, Apr 23, 2008 IP
    greatlogix likes this.
  6. CreativeClans

    CreativeClans Peon

    Messages:
    128
    Likes Received:
    4
    Best Answers:
    0
    Trophy Points:
    0
    #6
    Your problem is probably caused because your server has magic quotes enabled.
    Before doing anything with the user input, even passing it through mysql_real_escape_string, pass it through a function like this:
    
    function checkinput ($value)
    {
      if (get_magic_quotes_gpc()) 
      {
        return stripslashes($value);
      }
      else
      {
        return $value;
      }
    }
    
    PHP:
     
    CreativeClans, Apr 23, 2008 IP
  7. Sabbir

    Sabbir Banned

    Messages:
    210
    Likes Received:
    6
    Best Answers:
    0
    Trophy Points:
    58
    #7
    means need to use stripslash 2 times. try to do that. let us know the status.
     
    Sabbir, Apr 23, 2008 IP
    greatlogix likes this.
  8. greatlogix

    greatlogix Active Member

    Messages:
    664
    Likes Received:
    13
    Best Answers:
    1
    Trophy Points:
    85
    #8
    Thanks CreativeClans and all it works. I did not notice there was addslashes call in the script. Nice code snippet. Thanks. Green rep to all :)

     
    greatlogix, Apr 23, 2008 IP