Sign in to follow this  
smitty1276

[web] Dumb SQL question...

Recommended Posts

It's been ages since I did this stuff, so pardom my stupidity on this... Can anyone tell me what the problem with this simple little php/mySQL statement is?
mysql_query(
"CREATE TABLE $usersGroupsTableName (
    user_id INT NOT NULL,
    group_id INT NOT NULL);"
) or die(mysql_error());

Produces the following 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 '( user_id INT NOT NULL, group_id INT NOT NULL)' at line 1. Maybe I'm missing something (obviously :-) ) but I'm not seeing a syntax problem.

Share this post


Link to post
Share on other sites
go here http://dev.mysql.com/doc/ and make sure you lookup the syntax for the correct version of MySQL ... it isn't exactly the same between 3.23, 4.0, 4.1, and 5.0

Share this post


Link to post
Share on other sites
Oh, goodness... ok, I got it working. I had initialized $usersGroupTableName but used $usersGroupsTableName ("group" not pluralized in initializer as it should have been)

Dumb mistake. Thanks for taking a look, though.

Share this post


Link to post
Share on other sites
we've all done it many times ... its the one weakness of working in languages that don't use variable declarations (I love my ruby but I've made been bitten by typos a few times myself).

good luck to you.

Share this post


Link to post
Share on other sites
Something that helped me infinitely when working with PHP/SQL was to dump the query to a string rather than creating the string inline in the mysql_query statement. Then when you have problems you turn on logging where just before you make each query, you print the string to the page. When the query fails you have the string printed to your browser and you can validate it. You can also then copy/paste it into a terminal window that's connected directly to your SQL database. You'll sometimes get slightly different error messages that way that can help you get to the bug.

-me

Share this post


Link to post
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

Sign in to follow this