SitePoint Sponsor

User Tag List

Results 1 to 5 of 5
  1. #1
    SitePoint Zealot
    Join Date
    Jan 2005
    Location
    md
    Posts
    180
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Inserting into database text that has parens

    Im trying to insert a string into a database that contains ( ) in the text, this seems to be breaking the query.... does anyone know how to do this?

    Thanks!

  2. #2
    Follow Me On Twitter: @djg gold trophysilver trophybronze trophy Dan Grossman's Avatar
    Join Date
    Aug 2000
    Location
    Philadephia, PA
    Posts
    20,578
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    Since all text type fields have to be surrounded by quotes in your query anyway, parentheses inside the string has no effect. If you're running into a problem because your input has parentheses in it, you're doing something else very wrong.

    This would run just fine:

    PHP Code:
    $name "Dan";
    $favoriteColor "Blue (or cyan)";
    mysql_query("INSERT INTO table (name, favoriteColor) VALUES ('$name', '$favoriteColor')"$connection); 
    Other characters might give you problems if you don't handle them somewhere, like quotes. You should pass your input through mysql_real_escape_string() before using it in a query at the least.

  3. #3
    SitePoint Zealot
    Join Date
    Jan 2005
    Location
    md
    Posts
    180
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hi Dan, I'm trying to use the mysql_real_excape_string but I always receive an error "Called to undified function"... isnt this a built in function?

  4. #4
    Follow Me On Twitter: @djg gold trophysilver trophybronze trophy Dan Grossman's Avatar
    Join Date
    Aug 2000
    Location
    Philadephia, PA
    Posts
    20,578
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    You may have a very old copy of PHP on your server. That function is listed in the manual as 4.3.0+ or 5.0+.

  5. #5
    SitePoint Addict molder101's Avatar
    Join Date
    Apr 2004
    Location
    dorothy
    Posts
    234
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by Gexus
    Hi Dan, I'm trying to use the mysql_real_excape_string but I always receive an error "Called to undified function"... isnt this a built in function?
    I take it the above is supposed to be mysql_real_escape_string? (no "x")... it was implemented in 4.3.0. So anything <= and you are good to go!
    Michael R. Sikora
    www.blue-eyedesign.com
    {redesigning web design}


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
  •