Jump to content


Photo

Error using CURDATE()


  • Please log in to reply
6 replies to this topic

#1 Eskimo887

Eskimo887
  • Members
  • PipPip
  • Member
  • 13 posts

Posted 21 July 2006 - 11:16 AM

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:

$sql = "INSERT INTO roster SET " . "first_name='$first', " . "last_name='$last', " . "email='$email', " . "password='$password', " . "join=CURDATE()";

But, when I submit the form, I get the 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 'join=CURDATE()' at line 1


What is wrong with my syntax, as I have another INSERT query that uses exactly the same thing.

#2 shoz

shoz
  • Staff Alumni
  • Advanced Member
  • 600 posts

Posted 21 July 2006 - 01:57 PM

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:

$sql = "INSERT INTO roster SET " . "first_name='$first', " . "last_name='$last', " . "email='$email', " . "password='$password', " . "join=CURDATE()";

But, when I submit the form, I get the 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 'join=CURDATE()' at line 1


What is wrong with my syntax, as I have another INSERT query that uses exactly the same thing.


"join" is a reserved word you can either surround the column name with backticks (``) or change the column name.

I'd recommend you change the column name.

#3 fenway

fenway
  • Staff Alumni
  • MySQL Si-Fu / PHP Resident Alien
  • 16,199 posts
  • LocationToronto, ON

Posted 21 July 2006 - 07:47 PM

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.
Seriously... if people don't start reading this before posting, I'm going to consider not answering at all.

#4 Eskimo887

Eskimo887
  • Members
  • PipPip
  • Member
  • 13 posts

Posted 22 July 2006 - 12:56 AM

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.

#5 shoz

shoz
  • Staff Alumni
  • Advanced Member
  • 600 posts

Posted 22 July 2006 - 03:40 AM

Use the following format when making the mysql_query call to make debugging easier.

$query = 'query here';
$result = mysql_query($query) or die('query: '.$query."<br />\n".mysql_error());

Post the output here.

#6 Eskimo887

Eskimo887
  • Members
  • PipPip
  • Member
  • 13 posts

Posted 22 July 2006 - 04:35 AM

It's working now, I got the answer from another forum, it was just encasing the queries with {} is seems.

#7 fenway

fenway
  • Staff Alumni
  • MySQL Si-Fu / PHP Resident Alien
  • 16,199 posts
  • LocationToronto, ON

Posted 22 July 2006 - 04:12 PM

Curlies? Really?
Seriously... if people don't start reading this before posting, I'm going to consider not answering at all.




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users