Results 1 to 3 of 3

Thread: Problems with quotes after moving database

  1. #1
    Join Date
    Apr 2008
    Posts
    5
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default Problems with quotes after moving database

    Hi to all,

    I moved a db from a website to another but i have big trouble with single/double quotes. I've recreated the site and built a new database with the same name as the original database. When I try to update an old article on the website I get the following error..

    I'm givin' her all she's got, Captain, but we need more power!
    This error said :
    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 've seen and manage your video collection.', `DESCRIPTION` = 'Coollector is a gre' at line 1
    And this because the description of the article contains a single quote:

    Coollector Movie Database: track the movies you've seen and manage your video collection.
    The old website MySQL version: 5.0.81
    The new website MySQL version: 5.1.30

    Pls. help me with a simple soution, it's been two days since i try and i try and I'm going crazy.

    Thank you in advance.

  2. #2
    Join Date
    Apr 2009
    Location
    Cognac, France
    Posts
    400
    Thanks
    2
    Thanked 57 Times in 57 Posts

    Default

    Without seeing your PHP code this is caused by the ' in the string.

    This would cause your problem.

    PHP Code:
    $string="I'm givin' her all she's got, Captain, but we need more power!";

    $result mysql_query ("INSERT INTO table (field) VALUES ('$string')"); 
    There are 2 many single quotes in the field insert value.

    If you do this, using the "american" quotes, it should work

    PHP Code:
    $string="I'm givin' her all she's got, Captain, but we need more power!";

    $result mysql_query ("INSERT INTO table (field) VALUES (`$string`)"); 

  3. #3
    Join Date
    Sep 2008
    Location
    Bristol - UK
    Posts
    842
    Thanks
    32
    Thanked 132 Times in 131 Posts

    Default

    Following on from what amnesiac has said, you could keep the string in single quotes, but just escape them:

    PHP Code:
    $string='I\'m givin\' her all she\'s got, Captain, but we need more power!'

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
  •