Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 8 of 8
  1. #1
    New Coder
    Join Date
    Apr 2009
    Location
    Denmark <'3
    Posts
    44
    Thanks
    5
    Thanked 1 Time in 1 Post

    Question Help mysql error .

    Hey i keep getting an error with this :

    PHP Code:
    $q2 mysql_query("INSERT INTO pcpin_nickname (user_id, nickname, nickname_plain, default) VALUES('$user_id', '$nickname', '$usnm[$number]', 'y')") or print("&nbsp;&nbsp;&nbsp;Failed creating nick_name for user: '$usnm[$number]' : " mysql_error()); 
    the error is :
    Failed creating nick_name for user: 'Diload' : 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 'default) VALUES('1', '^ff0000Diload', 'Diload', 'y')' at line 1

    I appreciate any help
    and please don't be afraid to ask any questions

    Regards
    Last edited by diload; 01-18-2010 at 04:30 PM. Reason: Resolved :)

  • #2
    Senior Coder
    Join Date
    May 2005
    Posts
    2,137
    Thanks
    96
    Thanked 72 Times in 72 Posts
    The problem is $usnm[$number] doesn't hold a value. Try either ".$usnm['$number']." or put '0' just to test it.
    Rowsdower! has accused me of having mental problems, and the administrator allowed it. What a great forum huh?

  • #3
    New Coder
    Join Date
    Jan 2010
    Location
    UT
    Posts
    35
    Thanks
    1
    Thanked 3 Times in 3 Posts
    "default" is a reserved word in mysql, you need to change the name of your field. That should fix your error.

    // edit: you can view the complete list of reserved words at http://dev.mysql.com/doc/refman/5.1/...ved-words.html

  • Users who have thanked Zoic for this post:

    diload (01-18-2010)

  • #4
    bdl
    bdl is offline
    Regular Coder
    Join Date
    Apr 2007
    Location
    Camarillo, CA US
    Posts
    590
    Thanks
    4
    Thanked 83 Times in 82 Posts
    Zoic beat me to it. The clue to almost every MySQL error message is in the message itself, in this case, 'default' is the first word in the actual error.

    ...right syntax to use near 'default)...

  • #5
    Regular Coder
    Join Date
    Dec 2009
    Location
    UK
    Posts
    495
    Thanks
    0
    Thanked 58 Times in 58 Posts
    You can also correct this by adding backticks to your SQL query
    PHP Code:
    $q2 mysql_query("INSERT INTO pcpin_nickname (user_id, nickname, nickname_plain, `default`) VALUES('$user_id', '$nickname', '$usnm[$number]', 'y')") or print("&nbsp;&nbsp;&nbsp;Failed creating nick_name for user: '$usnm[$number]' : " mysql_error()); 
    It's recommended that you put backticks around all field and table names to avoid this from happening
    My site: JayGilford.com
    Resources:
    PHP Pagination Class | Getting all page links | Handling PHP Errors properly
    If you like a users help, show your appreciation with the rep and thanks buttons :)

  • #6
    bdl
    bdl is offline
    Regular Coder
    Join Date
    Apr 2007
    Location
    Camarillo, CA US
    Posts
    590
    Thanks
    4
    Thanked 83 Times in 82 Posts
    Quote Originally Posted by JAY6390 View Post
    You can also correct this by adding backticks to your SQL query
    ...
    It's recommended that you put backticks around all field and table names to avoid this from happening
    Well, I agree with you but the SQL nazis usually jump all over this. You should always use unique, relevant table / field names. Barring that, you can use `backticks` in a pinch. I use them myself to make the field names 'pop' in my statements, not to avoid reserved word collisions.

    This problem usually rears its ugly head when using the ubiquitous phpMyAdmin software; it allows you to name your fields with whatever you want, and silently uses `backticks` in its statements. When you go to use those fields in your script, BAM you get errors like this every time.

  • #7
    Regular Coder
    Join Date
    Dec 2009
    Location
    UK
    Posts
    495
    Thanks
    0
    Thanked 58 Times in 58 Posts
    This is why I don't use PMA. Navicat FTW!
    My site: JayGilford.com
    Resources:
    PHP Pagination Class | Getting all page links | Handling PHP Errors properly
    If you like a users help, show your appreciation with the rep and thanks buttons :)

  • #8
    New Coder
    Join Date
    Apr 2009
    Location
    Denmark <'3
    Posts
    44
    Thanks
    5
    Thanked 1 Time in 1 Post
    Thanks all Didn't really think about that
    If i've created that DB myself I would probably have thought about it but I'm creating a script to convert users from "PHP-fusion" (A Opensource CMS system) to PCPIN chat (A open source php/ajax chat)

    Once again thanks for the answers


  •  

    Posting Permissions

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