Eskimo887 Posted July 21, 2006 Share Posted July 21, 2006 I have a join form on my website which adds the current date to the database so I know when people have joined.For this, my INSERT query looks like:[code] $sql = "INSERT INTO roster SET " . "first_name='$first', " . "last_name='$last', " . "email='$email', " . "password='$password', " . "join=CURDATE()";[/code]But, when I submit the form, I get the error:[quote]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 'join=CURDATE()' at line 1[/quote]What is wrong with my syntax, as I have another INSERT query that uses exactly the same thing. Quote Link to comment Share on other sites More sharing options...
shoz Posted July 21, 2006 Share Posted July 21, 2006 [quote author=Eskimo887 link=topic=101366.msg401099#msg401099 date=1153480619]I have a join form on my website which adds the current date to the database so I know when people have joined.For this, my INSERT query looks like:[code] $sql = "INSERT INTO roster SET " . "first_name='$first', " . "last_name='$last', " . "email='$email', " . "password='$password', " . "join=CURDATE()";[/code]But, when I submit the form, I get the error:[quote]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 'join=CURDATE()' at line 1[/quote]What is wrong with my syntax, as I have another INSERT query that uses exactly the same thing.[/quote]"join" is a [url=http://dev.mysql.com/doc/refman/4.1/en/reserved-words.html]reserved word[/url] you can either surround the column name with backticks (``) or change the column name.I'd recommend you change the column name. Quote Link to comment Share on other sites More sharing options...
fenway Posted July 21, 2006 Share Posted July 21, 2006 In general, if you use descriptive column names, with two words, separated by an underscore, you'll always be fine, and almost never run into reserved keywords. Quote Link to comment Share on other sites More sharing options...
Eskimo887 Posted July 22, 2006 Author Share Posted July 22, 2006 I have changed the column name to "date" and I'm still getting the same error. I also used join_date with the same effect. Quote Link to comment Share on other sites More sharing options...
shoz Posted July 22, 2006 Share Posted July 22, 2006 Use the following format when making the mysql_query call to make debugging easier.[code]$query = 'query here';$result = mysql_query($query) or die('query: '.$query."<br />\n".mysql_error());[/code]Post the output here. Quote Link to comment Share on other sites More sharing options...
Eskimo887 Posted July 22, 2006 Author Share Posted July 22, 2006 It's working now, I got the answer from another forum, it was just encasing the queries with {} is seems. Quote Link to comment Share on other sites More sharing options...
fenway Posted July 22, 2006 Share Posted July 22, 2006 Curlies? Really? Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.