Jump to content

Error using CURDATE()


Eskimo887

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

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

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.