/    Sign up×
Community /Pin to ProfileBookmark

mysql query problem

ok, ive got this query:

[code=php]$query = “INSERT INTO `gallery` ( `location` , `name` , `caption` , `group` ) VALUES ( `$dbLocation` , `$dbFileName` , `$dbCaption` , `$dbGroup` )”;
$result = mysql_query($query) or die (‘Couldnt run query: ‘.$query.’ – Error: ‘.mysql_error());[/code]

the problem is whenever i run the query i get this error:

[QUOTE]

Couldnt run query: INSERT INTO `gallery` ( `location` , `name` , `caption` , `group` ) VALUES ( `/CPA Band/admin/uploaded_files/1163911098-8P.JPG` , `1163911098-8P.JPG` , `Woop!` , `test1` ) – Error: Unknown column ‘/CPA Band/admin/uploaded_files/1163911098-8P.JPG’ in ‘field list’

[/QUOTE]

any suggestions on what could be causing this would be great, probally something simple, ive checked the spelling and even copy and pasted and that didnt work, so any suggestions would be great.

to post a comment
PHP

4 Comments(s)

Copy linkTweet thisAlerts:
@chazzyNov 19.2006 — with mysql, you enclose your column names with back ticks (), but you enclose your string data in single quotes (')

So that means your code should be

<CODE lang="php">[code=php]<i>
</i> $query = "INSERT INTO
gallery ( location , name , caption , group` ) VALUES ( '$dbLocation' , '$dbFileName' , '$dbCaption' , '$dbGroup' )";
$result = mysql_query($query) or die ('Couldnt run query: '.$query.' - Error: '.mysql_error());
[/code]
Copy linkTweet thisAlerts:
@1andywNov 19.2006 — with mysql, you enclose your column names with back ticks (`), but you enclose your string data in single quotes (')

Chazzy,

Will you provide a link explaining why this is necessary?

Andy
Copy linkTweet thisAlerts:
@chazzyNov 19.2006 — with mysql, you enclose your column names with back ticks (`), but you enclose your string data in single quotes (')

Chazzy,

Will you provide a link explaining why this is necessary?

Andy[/QUOTE]


Sure.

This explains strings

http://dev.mysql.com/doc/refman/5.0/en/string-syntax.html

This explains "names"

http://dev.mysql.com/doc/refman/5.0/en/legal-names.html
Copy linkTweet thisAlerts:
@welshauthorNov 19.2006 — thanks chazzy, i knew it would be something simple.
×

Success!

Help @welsh spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.28,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...