How do I get round using a delimiter

Discussion in 'PHP' started by countrydj, Jan 3, 2011.

  1. #1
    Happy New Year everybody...

    I have moved my notice board from a server running php 3 and mysql 3 to a server running php 5 and mysql 5.

    On the old server, if somebody wrote " it's mine" it would accept it into the database.
    On the new server, if somebody wrote "it's mine" the database won't accept it.
    They have to write "it\'s mine". The user won't get round this.

    How can I get round it?

    Regards,

    John C
     
    countrydj, Jan 3, 2011 IP
  2. dsdf

    dsdf Peon

    Messages:
    35
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #2
    use this function:
    mysql_real_escape_string($string);
     
    dsdf, Jan 3, 2011 IP
  3. countrydj

    countrydj Active Member

    Messages:
    41
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    91
    #3
    Hi dsdf...
    Many thanks for your quick reply.
    However, I'm quite new to php so I don't fully understand.
    Can you give me some more guidance.

    I place a notice: It's me.This is the response:
    Error in executing INSERT INTO epals (id,reference,realname,email,city,country,days,interests,age,gender,type,remoteip,postdate,enddate,end,status)VALUES ('','2592','wecfwe','wefe','efcwe','wefwe','90','It's me','45 to 55','Male','ep','88.97.199.150','Monday 3rd of January 2011 at 13:59:57','03rd April 2011','04/03/2011','') query
    error:1064 You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 's me','45 to 55','Male','ep','88.97.199.150','Monday 3rd of January 2011 at 13:5' at line 1


    Can you understand this ??

    Cheers,

    John C
     
    countrydj, Jan 3, 2011 IP
  4. dsdf

    dsdf Peon

    Messages:
    35
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #4
    I recommend you to build a function and add mysql_real_escape_string($string) on there.

    For example:

    function change_string($string) {
    return mysql_real_escape_string($string);
    }

    $interest = change_string("it's me");

    $command = "INSERT INTO epals (id,reference,realname,email,city,country,days,interests,age,gender,type,remoteip,postdate,enddate,end,status)VALUES ('','2592','wecfwe','wefe','efcwe','wefwe','90',$interest,'45 to 55','Male','ep','88.97.199.150','Monday 3rd of January 2011 at 13:59:57','03rd April 2011','04/03/2011','');
     
    dsdf, Jan 3, 2011 IP
  5. Moustafa.Elkady

    Moustafa.Elkady Member

    Messages:
    24
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    31
    #5
    what about this snippet
    function _clean($str){
        return is_array($str) ? array_map('_clean', $str) : 
               str_replace('\\', '\\\\',
                          htmlspecialchars(
                                           (get_magic_quotes_gpc() ?
               stripslashes($str) : $str), ENT_QUOTES));
    }
    PHP:
    :
    source:
    http://www.jooria.com/snippets?snippet=123
    Code (markup):
     
    Moustafa.Elkady, Jan 3, 2011 IP
  6. countrydj

    countrydj Active Member

    Messages:
    41
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    91
    #6
    Hi Guys...
    Many thanks for your suggestions.
    I've messed about all afternoon without success.
    However, I took a look in php.ini file and TURNED ON magic_quotes_gpc = On
    This solved the problem for me.
    Thanks for trying to help. I appreciate it.

    Kind regards

    John C
     
    countrydj, Jan 3, 2011 IP
  7. tprinty

    tprinty Peon

    Messages:
    10
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #7
    you can use the addslashes() stripslashes() functions to make sure things are escaped and not escaped correctly.
     
    tprinty, Jan 3, 2011 IP
  8. countrydj

    countrydj Active Member

    Messages:
    41
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    91
    #8
    Hi tprinty...
    Thanks for your advice.
    Unfortunately I'm not too good at programming so I tend to take the easy way out.
     
    countrydj, Jan 3, 2011 IP