Php Problem

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts
  • Phoubers
    Sergeant

    • Oct 2007
    • 34

    Php Problem

    Hello,
    I am having a php problem and I looked all over the internet and different search engines for the answer... I have already posted this a long time ago but now it is edited.
    Note: My connection to the database is stable
    __________________________________________________ ___________
    $query = ("INSERT INTO users (firstname, lastname, username, password, email, date, rank, status, key) VALUES('$first', '$last', '$username', '$password', '$email', '$date', '$rank', '$status', '$key')");
    if (!mysql_query($query, $con)) {
    die('ERROR: ' . mysql_error());
    }
    ŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻ ŻŻŻŻŻŻŻŻŻŻŻ
    I have rewritten an old code and seem to be having a problem writing data to my database. I receive this error

    ERROR: 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 'key) VALUES ('Matt', 'Pomeranz', 'Phoubers', 'password' at line 1
    No its not Fowbers its foobers :D
  • Watdaflip
    Major General

    • Sep 2005
    • 2116

    #2
    Re: Php Problem

    First of all you should change your error handling. You need to close the database connection, so you should either make it
    PHP Code:
     if (!mysql_query($query$con)) {
    mysql_close($con);
      die(
    'ERROR: ' mysql_error());
     } 
    of just echo an error message and set a flag if needed...


    Anyway, on to the error.

    You need to change the name of the column "key" to something else, the word "key" is a reserved word in both php and mysql. Its fine to use it as a variable name (ie. $key is fine), but you can't use it as a column name in a database table. Once you change that the query should work fine.



    PS. In your variables, you don't have to surround them with ().

    For instance you have $query = ("");

    You can just format it like $query = "";

    Its not wrong, it still works, its just more work for you to type it, and for anyone else reading through your code it can make it less readable (depending on what else is being done). Just FYI.

    Register/Login Script
    Do you use a Password Protected Directory? Need a way to allow users to make their own account, try my .htaccess Login Script

    Comment

    • Phoubers
      Sergeant

      • Oct 2007
      • 34

      #3
      Re: Php Problem

      After all the time I spent trying to figure it out..it was the word key. Thanks so much watdaflip your a genius. And those hints you gave me, Ill get on that right away.

      Thank you
      No its not Fowbers its foobers :D

      Comment

      Working...
      X