php mysql ' character issue

Discussion in 'PHP' started by protocol96, May 30, 2007.

  1. #1
    i have a string variable which has these characters-> ' in between them, so wen i try to insert the values into the my database it gives me an error. Any thing that can be done about it?
     
    protocol96, May 30, 2007 IP
  2. nico_swd

    nico_swd Prominent Member

    Messages:
    4,153
    Likes Received:
    344
    Best Answers:
    18
    Trophy Points:
    375
  3. protocol96

    protocol96 Peon

    Messages:
    413
    Likes Received:
    7
    Best Answers:
    0
    Trophy Points:
    0
    #3
    yea, that was useful, but now the issue i m facing is, those variables also have / in the starting and end, i cannot use str_replace and replace them as i need / in the middle of the string also the string has special characters
     
    protocol96, May 30, 2007 IP
  4. nico_swd

    nico_swd Prominent Member

    Messages:
    4,153
    Likes Received:
    344
    Best Answers:
    18
    Trophy Points:
    375
    #4
    Where's the problem?

    Forward slashes remain untouched. Don't use stripslashes() as they suggest. Just apply mysql_real_escape_string() once on the variable you want to insert and it should work.

    Alternatively, you can try addslashes().
     
    nico_swd, May 30, 2007 IP
  5. protocol96

    protocol96 Peon

    Messages:
    413
    Likes Received:
    7
    Best Answers:
    0
    Trophy Points:
    0
    #5
    here the variable /hÁme/sweethÁme/, now i want it to look like hÁme/sweethÁme
     
    protocol96, May 30, 2007 IP
  6. gibex

    gibex Active Member

    Messages:
    1,060
    Likes Received:
    21
    Best Answers:
    0
    Trophy Points:
    95
    #6
    if you have magic quotes On, you have to use stripslashes before mysql_real_escape_string, otherwise you will have \\' instead of \'
     
    gibex, May 30, 2007 IP
  7. olddocks

    olddocks Notable Member

    Messages:
    3,275
    Likes Received:
    165
    Best Answers:
    0
    Trophy Points:
    215
    #7
    Use ` for fields and ' for values. What error you get?

    It should be like

     
    olddocks, May 30, 2007 IP
  8. HuggyCT2

    HuggyCT2 Guest

    Messages:
    222
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    0
    #8
    You dont need to place ` at all, but with a $var which you will be placing as a value you will need '$var', you will get a error if you state

    
    $query = "INSERT INTO `table` (name, age) VALUES ('$name', '$age')";
    
    // should be
    
    $query = "INSERT INTO table (name, age) VALUES ('$name', '$age')";
    
    
    PHP:
     
    HuggyCT2, May 30, 2007 IP
  9. krt

    krt Well-Known Member

    Messages:
    829
    Likes Received:
    38
    Best Answers:
    0
    Trophy Points:
    120
    #9
    trim($variable, '/');
    PHP:
     
    krt, May 30, 2007 IP
    protocol96 likes this.