Jump to content

Archived

This topic is now archived and is closed to further replies.

Eskimo887

Error using CURDATE()

Recommended Posts

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.

Share this post


Link to post
Share on other sites
[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.

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
It's working now, I got the answer from another forum, it was just encasing the queries with {} is seems.

Share this post


Link to post
Share on other sites
Curlies? Really?

Share this post


Link to post
Share on other sites

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.