hybrid kill3r Posted May 23, 2011 Share Posted May 23, 2011 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 Link to comment Share on other sites More sharing options...
2old2learn? Posted May 23, 2011 Share Posted May 23, 2011 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 More sharing options...
hybrid kill3r Posted May 23, 2011 Author Share Posted May 23, 2011 that doesn't help me... at all. try again. Link to comment Share on other sites More sharing options...
2old2learn? Posted May 23, 2011 Share Posted May 23, 2011 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"); Link to comment Share on other sites More sharing options...
jeffman Posted May 23, 2011 Share Posted May 23, 2011 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 More sharing options...
jeffman Posted May 23, 2011 Share Posted May 23, 2011 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 More sharing options...
thescientist Posted May 23, 2011 Share Posted May 23, 2011 that doesn't help me... at all. try again.nice way to respond to people trying to help you. Link to comment Share on other sites More sharing options...
2old2learn? Posted May 23, 2011 Share Posted May 23, 2011 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 More sharing options...
jeffman Posted May 23, 2011 Share Posted May 23, 2011 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 More sharing options...
2old2learn? Posted May 23, 2011 Share Posted May 23, 2011 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 More sharing options...
hybrid kill3r Posted May 23, 2011 Author Share Posted May 23, 2011 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. all that article explains is how to use it with php... not sql syntax. Link to comment Share on other sites More sharing options...
jeffman Posted May 23, 2011 Share Posted May 23, 2011 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. Link to comment Share on other sites More sharing options...
hybrid kill3r Posted May 23, 2011 Author Share Posted May 23, 2011 and the reserved word was the case. i changed the word "create" in my column name to start and it fixed it. thank you for your time. Link to comment Share on other sites More sharing options...
jeffman Posted May 23, 2011 Share Posted May 23, 2011 Good choice. Link to comment Share on other sites More sharing options...
2old2learn? Posted May 23, 2011 Share Posted May 23, 2011 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 More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.