MySQL-fgets Apostrophe Problem

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • forexgump@gmail.com

    #1

    MySQL-fgets Apostrophe Problem

    I have a PHP script where I extract data from a file and insert it into
    a MySQL database.

    Every time I run the PHP script I receive an SQL error that states:
    "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" ... and then it quotes a line from the file (where I'm trying to
    extract the data from) starting with an apostrophe.

    As an example, if the file (that I'm trying to extract data from) has
    ONLY the following line:
    "Hello, I don't know what's going on??"

    The full error returned by SQL will be...
    "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 't know what's going on??"

    I use the fgets function to extract the data from the file - if this
    helps in determining the problem.

    Can anyone offer any help as to why I'm receiving this error? I've been
    Googling away but can't seem to find any logical answer.

    Thanks,

    Ryan

  • forexgump@gmail.com

    #2
    Re: MySQL-fgets Apostrophe Problem

    Found the answer after the first search on Yahoo!!

    All I had to do was use the addslashes() php function.


    Ryan

    Comment

    Working...