Results 1 to 13 of 13

Thread: Quotes in MySQL

  1. #1

    Thread Starter
    WiggleWiggle dclamp's Avatar
    Join Date
    Aug 2006
    Posts
    3,527

    Quotes in MySQL

    How come when i put quotes into MySQL it displays with backslashes?
    My usual boring signature: Something

  2. #2
    PowerPoster
    Join Date
    Sep 2003
    Location
    Edmonton, AB, Canada
    Posts
    2,629

    Re: Quotes in MySQL

    uhh. put them in how?

    it won't add backslashes to anything unless you do it yourself using some function.
    Like Archer? Check out some Sterling Archer quotes.

  3. #3
    Kitten CornedBee's Avatar
    Join Date
    Aug 2001
    Location
    In a microchip!
    Posts
    11,594

    Re: Quotes in MySQL

    Yes it will, if you use the magic_quotes misfeature. (It's enabled by default on most PHP installations.)
    All the buzzt
    CornedBee

    "Writing specifications is like writing a novel. Writing code is like writing poetry."
    - Anonymous, published by Raymond Chen

    Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.

  4. #4

    Thread Starter
    WiggleWiggle dclamp's Avatar
    Join Date
    Aug 2006
    Posts
    3,527

    Re: Quotes in MySQL

    Quote Originally Posted by CornedBee
    Yes it will, if you use the magic_quotes misfeature. (It's enabled by default on most PHP installations.)

    how do you reverse this mis-feature?
    My usual boring signature: Something

  5. #5
    Junior Member hairball's Avatar
    Join Date
    Aug 2006
    Location
    i'm not here.
    Posts
    24

    Re: Quotes in MySQL

    You can change it in php.ini

    It looks something like this:

    Code:
    ; Magic quotes for incoming GET/POST/Cookie data.
    magic_quotes_gpc = On
    
    ; Magic quotes for runtime-generated data, e.g. data from SQL, from exec(), etc.
    magic_quotes_runtime = Off
    
    ; Use Sybase-style magic quotes (escape ' with '' instead of \').
    magic_quotes_sybase = Off
    or you can use the stripslashes function.

    Break out from your mental box.
    I found better company. Iced chocolate with coffee jelly, anyone?

  6. #6

    Thread Starter
    WiggleWiggle dclamp's Avatar
    Join Date
    Aug 2006
    Posts
    3,527

    Re: Quotes in MySQL

    where is the php.ini located?
    My usual boring signature: Something

  7. #7
    Junior Member hairball's Avatar
    Join Date
    Aug 2006
    Location
    i'm not here.
    Posts
    24

    Re: Quotes in MySQL

    If you are using Windows... it's either under Windows directory or your PHP directory.

    If you are using Linux... try the command: locate php.ini
    Mine is located in /usr/local/php/lib/php.ini

    Before you try editing anything. Backup a copy.
    Restart your server after editing php.ini for changes to take effect.

    Break out from your mental box.
    I found better company. Iced chocolate with coffee jelly, anyone?

  8. #8
    PowerPoster
    Join Date
    Sep 2003
    Location
    Edmonton, AB, Canada
    Posts
    2,629

    Re: Quotes in MySQL

    if your website is using a shared web hosting plan, you can probably -not- change the php.ini. you can try putting a ticket in to petition the option being changed, but other than that you are probably out of luck in that department. i did some looking around in the php functions, but couldn't find anything to disable magic_quotes_gpc.

    however, by default, on windows systems the ini file is installed to C:/Windows/
    Like Archer? Check out some Sterling Archer quotes.

  9. #9

    Thread Starter
    WiggleWiggle dclamp's Avatar
    Join Date
    Aug 2006
    Posts
    3,527

    Re: Quotes in MySQL

    i am using cpanel and it says that i have "FreeBSD". and my hosting company sucks so they will not want to help me. lol. I will try to see if they will change it for me. Yeah, i am on shared hosting -unfortunanly-
    My usual boring signature: Something

  10. #10
    PowerPoster
    Join Date
    Sep 2003
    Location
    Edmonton, AB, Canada
    Posts
    2,629

    Re: Quotes in MySQL

    FreeBSD is a Unix based OS, but since you are on a shared hosting plan I highly doubt you can run any type of Unix command to find the files. the most you can do is send in a ticket and ask if they can change it (although I doubt they would, because with most shared webhosting plans, multiple accounts are using the same ini file on a given server, and a change like that could possibly break someone else's website.. might turn into some kind of vote thing for the accounts on that server, though..), otherwise you'll just have to remove the slashes yourself through functions.
    Like Archer? Check out some Sterling Archer quotes.

  11. #11
    Kitten CornedBee's Avatar
    Join Date
    Aug 2001
    Location
    In a microchip!
    Posts
    11,594

    Re: Quotes in MySQL

    Here's how to reverse the effect of magic_quotes: include this snippet at the top of every PHP file:
    Code:
    if(get_magic_quotes_gpc()) {
      foreach($_GET as $k => $v) {
        $_GET[$k] = stripslashes($v);
      }
      foreach($_POST as $k => $v) {
        $_POST[$k] = stripslashes($v);
      }
      foreach($_COOKIE as $k => $v) {
        $_COOKIE[$k] = stripslashes($v);
      }
    }
    All the buzzt
    CornedBee

    "Writing specifications is like writing a novel. Writing code is like writing poetry."
    - Anonymous, published by Raymond Chen

    Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.

  12. #12
    I'm about to be a PowerPoster!
    Join Date
    Jan 2005
    Location
    Everywhere
    Posts
    13,647

    Re: Quotes in MySQL

    Quote Originally Posted by CornedBee
    Here's how to reverse the effect of magic_quotes: include this snippet at the top of every PHP file:
    Code:
    if(get_magic_quotes_gpc()) {
      foreach($_GET as $k => $v) {
        $_GET[$k] = stripslashes($v);
      }
      foreach($_POST as $k => $v) {
        $_POST[$k] = stripslashes($v);
      }
      foreach($_COOKIE as $k => $v) {
        $_COOKIE[$k] = stripslashes($v);
      }
    }
    Unfortunately that only does a shallow reverse and magic quotes is a deep operation, so you will need something more like this:

    PHP Code:
    if (get_magic_quotes_gpc()) {
      
    array_walk_recursive($_GET$rv_func create_function('$n''stripslashes($n);'));
      
    array_walk_recursive($_POST$rv_func);
      
    array_walk_recursive($_COOKIE$rv_func);

    There are also some other things that are affected by it, can't remember them off the top of my head right now.

  13. #13
    Kitten CornedBee's Avatar
    Join Date
    Aug 2001
    Location
    In a microchip!
    Posts
    11,594

    Re: Quotes in MySQL

    Didn't know it was recursive, though of course that makes sense. Good call.
    All the buzzt
    CornedBee

    "Writing specifications is like writing a novel. Writing code is like writing poetry."
    - Anonymous, published by Raymond Chen

    Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.

Posting Permissions

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



Click Here to Expand Forum to Full Width