Jump to content

MySQL Syntax Error


hybrid kill3r
 Share

Recommended Posts

What's wrong with my MySQL syntax?

$query = "			SELECT *			FROM forum_board_perms			WHERE group_id = ".$gid."			AND board_id = ".$bid."			AND {$action} = 1";

Prints the following query:SELECT * FROM forum_board_perms WHERE group_id = 1 AND board_id = 1 AND create = 1

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 'create = 1' at line 3
Edited by Hybrid Kill3r
Link to comment
Share on other sites

What's wrong with my MySQL syntax?
$query = "			SELECT *			FROM forum_board_perms			WHERE group_id = ".$gid."			AND board_id = ".$bid."			AND {$action} = 1";

Prints the following query:SELECT * FROM forum_board_perms WHERE group_id = 1 AND board_id = 1 AND create = 1

http://www.w3schools.com/php/php_mysql_select.asp
Link to comment
Share on other sites

What's wrong with my MySQL syntax?
$query = "			SELECT *			FROM forum_board_perms			WHERE group_id = ".$gid."			AND board_id = ".$bid."			AND {$action} = 1";

Prints the following query:SELECT * FROM forum_board_perms WHERE group_id = 1 AND board_id = 1 AND create = 1

shouldn't is be
$result = mysql_query("Select * From forum_board_perms WHERE group_id=".$gid" AND board_id=".$bid" And {$action}=1");

Edited by 2old2learn?
Link to comment
Share on other sites

1. create is a reserved word. Using a reserved word to name a field is a bad idea. I believe you can do it if you put the reserved word in [square brackets], but it would be better to change the name of the field.I also wonder if your field values are number types, since you are passing them as numbers, not string types.

Link to comment
Share on other sites

Actually, 2old2learn?, I recommend assigning query strings to a variable to simplify the process of debugging. If you pass the string as a literal to mysql_query, you have no way of knowing what it contains. If you assign it to a var, and pass the var to mysql_query, then if there is trouble, you have the var available for echo.

Link to comment
Share on other sites

1. create is a reserved word. Using a reserved word to name a field is a bad idea. I believe you can do it if you put the reserved word in [square brackets], but it would be better to change the name of the field.I also wonder if your field values are number types, since you are passing them as numbers, not string types.
LOL believe it or not before I added to this discussion I had also thought that the [square brackets] should be used..for the [$action]....
Link to comment
Share on other sites

The brackets should be used as a LAST RESORT, like if your client has an established database. If you're still developing it, you'll make everyone happier in the long run if you change the field name.

Link to comment
Share on other sites

Sorry the " create " field is wrong is what your saying in the " SELECT

SELECT * FROM forum_board_perms WHERE group_id = 1 AND board_id = 1 AND create = 1

It is as you say a reserve word.." create "

Link to comment
Share on other sites

nice way to respond to people trying to help you.
maybe if they would actually make an effort to help me instead of just posting a link.
Agreed, the help could have been more helpful. Maybe when you explain that you could add a word like "please" or "thank you." Common courtesy goes a long way when you're the one asking for something. Edited by Deirdre's Dad
Link to comment
Share on other sites

maybe if they would actually make an effort to help me instead of just posting a link. all that article explains is how to use it with php... not sql syntax.
I am sorry if you felt this wasn't enough..but as I found out in other sites other than here..all I got is a link to read up on to solve the problem..yes, I could have done more I agree but as I am finding out it doesn't help much unless you find the error yourself..you don't learn..I am still learning much about php...so at times my suggestion my be off by alot..but at least I make an effort...because even if I am wrong and then corrected I again learn something...myself...Your welcome...
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...