+ Reply to Thread
Results 1 to 3 of 3

Thread: Php Problem
      
   

  1. #1
    Phoubers's Avatar
    Phoubers is offline Sergeant
    Join Date
    Oct 2007
    Location
    :D
    Posts
    34

    Default 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

  2. #2
    Watdaflip's Avatar
    Watdaflip is offline Major General
    Join Date
    Sep 2005
    Location
    Cincinnati, Ohio
    Posts
    2,119

    Default 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

  3. #3
    Phoubers's Avatar
    Phoubers is offline Sergeant
    Join Date
    Oct 2007
    Location
    :D
    Posts
    34

    Smile 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

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

     

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49