Welcome Guest!
Please login
If you do not have an account yet on The Web Squeeze forums, please Register! It’s FREE and there are many benefits:
- Receive Fast Advice
- Learn Programming Languages
- Get Professional Website Reviews
- Quick Troubleshooting Assistance
|
|
Php Query Error.
This is a discussion on Php Query Error., within the PHP section. This forum and the thread "Php Query Error." are both part of the Programming Your Website category.
![]() ![]() |
Feb 14 2008, 10:06 AM
Post
#1
|
|
![]() Fresh Squeezed ![]() ![]() Group: Members Posts: 12 Joined: 14-February 08 From: Scotland Member No.: 88 |
Hey guys. This isn't so much a problem as a question..
I was playing about with comment posting and I had this (so I though) simple code in my script. CODE $sql = "INSERT INTO comments (user,from,comment,date) VALUES ('$id','$userID','$comment',NOW())"; I had to change it to CODE $sql = "INSERT INTO `theloop`.`comments` (`user`, `from`, `comment`, `date`) VALUES ('$id', '$userID', '$comment', CURRENT_TIMESTAMP);"; I don't see why the first one didn't work and the second one did. They're the same apart from having theloop.comments instead of just comments and CURRENT_TIMESTAMP instead of NOW(). Also when I tried putting CURRENT_TIMESTAMP in place of NOW it didn't work. Either did adding the DB name infront of the table. Can anyone spread some light on the situation? -------------------- |
|
|
Feb 14 2008, 02:42 PM
Post
#2
|
|
![]() Squeezing ![]() ![]() ![]() Group: Members Posts: 70 Joined: 14-February 08 From: Las Vegas, NV Member No.: 122 |
are you purposely inserting IDs as strings? And what does your connection string look like?
Hey guys. This isn't so much a problem as a question..
I was playing about with comment posting and I had this (so I though) simple code in my script. CODE $sql = "INSERT INTO comments (user,from,comment,date) VALUES ('$id','$userID','$comment',NOW())"; I had to change it to CODE $sql = "INSERT INTO `theloop`.`comments` (`user`, `from`, `comment`, `date`) VALUES ('$id', '$userID', '$comment', CURRENT_TIMESTAMP);"; I don't see why the first one didn't work and the second one did. They're the same apart from having theloop.comments instead of just comments and CURRENT_TIMESTAMP instead of NOW(). Also when I tried putting CURRENT_TIMESTAMP in place of NOW it didn't work. Either did adding the DB name infront of the table. Can anyone spread some light on the situation? -------------------- |
|
|
Feb 14 2008, 05:33 PM
Post
#3
|
|
![]() Rapid Squeezer ![]() ![]() ![]() ![]() Group: Mentor Posts: 223 Joined: 14-February 08 From: NY, USA Member No.: 127 |
Hey guys,
I have a feeling it has to do with your connection string, as Blake mentioned, but I'm not sure without seeing all the code. There's no reason that I know of that the MySql NOW() function would not work. I have a feeling it's because of a missing mysql_select_db() call before the mysql_query(). Rich -------------------- |
|
|
Feb 14 2008, 05:55 PM
Post
#4
|
|
![]() Fresh Squeezed ![]() ![]() Group: Members Posts: 12 Joined: 14-February 08 From: Scotland Member No.: 88 |
It's nothing to do with the connection.
I know the connection works fine, I have other query's that will run. It seems to fix it's self when you add those slanty commas around each element. Which makes no sense to me. -------------------- |
|
|
Feb 14 2008, 07:29 PM
Post
#5
|
|
![]() Rapid Squeezer ![]() ![]() ![]() ![]() Group: Mentor Posts: 223 Joined: 14-February 08 From: NY, USA Member No.: 127 |
OH...duh!
Reserved words. MySql has reserved words you cannot use unless quoted... http://dev.mysql.com/doc/refman/5.0/en/reserved-words.html While you're "ok" with an unquoted "date" (i.e.: select date from logs), you should make it a practice to never use reserved words as colum names. You should also make it a practice to quote all database, table and column names when you create your queries as well. (i.e.: SELECT `log_date` FROM `logs`) Take care, Rich -------------------- |
|
|
Feb 15 2008, 09:41 AM
Post
#6
|
|
![]() Fresh Squeezed ![]() ![]() Group: Members Posts: 12 Joined: 14-February 08 From: Scotland Member No.: 88 |
Ahh... I'm such an idiot. I didn't even think or reserved words.
Cheers mate! -------------------- |
|
|
If you found The Web Squeeze to be helpful, please donate so we can keep this site FREE, FRESH, and fortified with Web Design & Development info!
![]() ![]() |
1 User(s) are reading this topic (1 Guests and 0 Anonymous Users)
0 Members:
Similar Topics
| Topic Title | Replies | Topic Starter | Views | Last Action | |||
|---|---|---|---|---|---|---|---|
![]() |
4 | Sleaklight | 202 | 15th February 2008 - 03:25 PM Last post by: Marc |
|||
![]() |
9 | PoetAlley | 296 | 17th February 2008 - 06:27 PM Last post by: PoetAlley |
|||
![]() |
3 | mcdanielnc89 | 234 | 23rd February 2008 - 08:14 AM Last post by: Marc |
|||
![]() |
14 | JustinStudios | 274 | 17th March 2008 - 12:04 AM Last post by: Monie |
|||
![]() |
18 | Mark | 222 | 6th March 2008 - 12:40 PM Last post by: delusion |
|||






Feb 14 2008, 10:06 AM











