SQL insert error

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
pinehead18
Forum Contributor
Posts: 329
Joined: Thu Jul 31, 2003 9:20 pm

SQL insert error

Post by pinehead18 »

I'll tell you what, having a day job sucks. Apparently it makes me stupid at php

Code: Select all

$sql = "INSERT INTO scene (section, body, by, date, title) VALUES ('section', 'body', 'by', 'date', 'title')";
Is my code


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 'by, date, title) VALUES ('section', 'body', 'by', 'date', 'title')' at line 1

is my error.

Please help relieve my pain.
User avatar
Benjamin
Site Administrator
Posts: 6935
Joined: Sun May 19, 2002 10:24 pm

Post by Benjamin »

Some of your field names are reserved for use by mysql. Escape them with backticks. `
pinehead18
Forum Contributor
Posts: 329
Joined: Thu Jul 31, 2003 9:20 pm

Post by pinehead18 »

Backtick (i know i know) you mean \?
User avatar
Benjamin
Site Administrator
Posts: 6935
Joined: Sun May 19, 2002 10:24 pm

Post by Benjamin »

I mean `

Here is a bunch of them. ``````````````
bdlang
Forum Contributor
Posts: 395
Joined: Tue May 16, 2006 8:46 pm
Location: Ventura, CA US

Post by bdlang »

astions wrote:Some of your field names are reserved for use by mysql. Escape them with backticks. `
Alternatively, change your column names.

MySQL Reserved Words
TreyAU21
Forum Newbie
Posts: 9
Joined: Thu Apr 13, 2006 6:37 pm
Location: Woodstock, GA

Post by TreyAU21 »

Field Types could be an issue too. I'm not 100% sure, but if the date field is a DATE, DATETIME, or TIMESTAMP field, won't passing it a simple string crap out? Although... it might just fill it with '0000-00-00 00:00:00'... I can't remember. I'm a little shabby. :oops:
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

TreyAU21 wrote:Field Types could be an issue too. I'm not 100% sure, but if the date field is a DATE, DATETIME, or TIMESTAMP field, won't passing it a simple string crap out? Although... it might just fill it with '0000-00-00 00:00:00'... I can't remember. I'm a little shabby. :oops:
Simple strings are how DATE et al are set.
Post Reply