...

View Full Version : Resolved Help mysql error .



diload
01-17-2010, 10:02 PM
Hey i keep getting an error with this :


$q2 = mysql_query("INSERT INTO pcpin_nickname (user_id, nickname, nickname_plain, default) VALUES('$user_id', '$nickname', '$usnm[$number]', 'y')") or print("   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 :p

Regards :)

masterofollies
01-17-2010, 10:08 PM
The problem is $usnm[$number] doesn't hold a value. Try either ".$usnm['$number']." or put '0' just to test it.

Zoic
01-17-2010, 10:11 PM
"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/en/reserved-words.html

bdl
01-18-2010, 01:10 AM
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)...

JAY6390
01-18-2010, 01:44 AM
You can also correct this by adding backticks to your SQL query

$q2 = mysql_query("INSERT INTO pcpin_nickname (user_id, nickname, nickname_plain, `default`) VALUES('$user_id', '$nickname', '$usnm[$number]', 'y')") or print("   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

bdl
01-18-2010, 02:06 AM
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.

JAY6390
01-18-2010, 02:08 AM
This is why I don't use PMA. Navicat FTW! :)

diload
01-18-2010, 04:30 PM
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 :)



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum