Results 1 to 6 of 6

Thread: stripslashes() or addslashes() or magic_quotes_gpc

  1. #1
    Join Date
    Mar 2007
    Location
    Currently: New York/Philadelphia
    Posts
    2,735
    Thanks
    3
    Thanked 519 Times in 507 Posts

    Default stripslashes() or addslashes() or magic_quotes_gpc

    Hi guys...

    Ok, so here's the problem.

    I'm using TinyMCE (http://tinymce.moxiecode.com/) in a backend CMS application. I'm then uploading this content into a MySQL database.

    The problem is whenever someone types something with an apostrophe, it doesn't upload correctly to the DB. Of course, the apostrophe needs to be escaped.

    Is there a way to do this automatically, using stripslashes() or addslashes() for example.

    How would I go about implementing that?

  2. #2
    Join Date
    Jul 2006
    Location
    just north of Boston, MA
    Posts
    1,806
    Thanks
    13
    Thanked 72 Times in 72 Posts

    Default

    PHP Code:
    $tring str_replace("'""\'",$tring); 

  3. #3
    Join Date
    Jun 2007
    Posts
    543
    Thanks
    3
    Thanked 78 Times in 78 Posts
    Blog Entries
    1

    Default

    i would use what you first said because it is for esaping characters (' " \ and NULL):
    Code:
    $string = addslashes($upload);
    [Jasme Library (Javascript Motion Effects)] My Site
    /\/\@§†ê® §©®¡þ† /\/\@|{ê®
    There are 10 kinds of people in the world, those that understand binary and those that don't.

  4. #4
    Join Date
    Sep 2006
    Location
    St. George, UT
    Posts
    2,769
    Thanks
    3
    Thanked 157 Times in 155 Posts

    Default

    Or another thing you could use is addcslashes and stripcslashes.

    Hope this helps.
    "Computer games don't affect kids; I mean if Pac-Man affected us as kids, we'd all be running around in darkened rooms, munching magic pills and listening to repetitive electronic music." - Kristian Wilson, Nintendo, Inc, 1989
    TheUnlimitedHost | The Testing Site | Southern Utah Web Hosting and Design

  5. #5
    Join Date
    Mar 2007
    Location
    Currently: New York/Philadelphia
    Posts
    2,735
    Thanks
    3
    Thanked 519 Times in 507 Posts

    Default

    how would i add that to my code?

    say, i have something like this:

    PHP Code:
    $summary $_POST['summary']; 
    how do i add the addslashes() or whatever else you suggest to it?

    or should i add a secondary step, such as below?

    PHP Code:
    $s $_POST['summary'];
    $summaryaddslashes($s); 

  6. #6
    Join Date
    Jun 2005
    Location
    英国
    Posts
    11,876
    Thanks
    1
    Thanked 180 Times in 172 Posts
    Blog Entries
    2

    Default

    If you're using it in an SQL query you should be using mysql_real_escape_string(). An ORM like Propel will also take care of this for you.
    Twey | I understand English | 日本語が分かります | mi jimpe fi le jbobau | mi esperanton komprenas | je comprends français | entiendo español | tôi ít hiểu tiếng Việt | ich verstehe ein bisschen Deutsch | beware XHTML | common coding mistakes | tutorials | various stuff | argh PHP!

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
  •