/    Sign up×
Community /Pin to ProfileBookmark

[RESOLVED] mysql update

I am running PHP 5.2.0 and mysql 5.0.19

This is my database structure and i am trying to update one feild.

[code]
Field Type Null Default
id smallint(10) No
full varchar(60) No
small varchar(60) No
company varchar(60) No
url varchar(100) No
description longtext No
count int(10) No 0
[/code]

[code=php]
mysql_query(“UPDATE “.$database.” SET count = (count+1) WHERE url = ‘”.$url.”‘ “) or die (“Can not update database, please try again. 1 ::<br /><br /> ” . mysql_error ());
[/code]

but i keep getting this error and i can’t see where i am wrong.

[code=php]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 ‘SET count = (count+1) WHERE url = ‘http://www.inboxdesign.co.nz” at line 1[/code]

Thanks

here is a print out of the query

[code=php]UPDATE portfolio SET count = (count+1) WHERE url = ‘http://www.inboxdesign.co.nz’ [/code]

to post a comment
PHP

7 Comments(s)

Copy linkTweet thisAlerts:
@NogDogJan 13.2007 — You might want to try something like this:
[code=php]
$sql = "UPDATE $database SET count = (count+1) WHERE url = '". mysql_real_escape_string($url)."'";
$result = mysql_query($sql) or die("Can not update database.<br />$sql<br />" . mysql_error());
[/code]
Copy linkTweet thisAlerts:
@NightShift58Jan 14.2007 — $sql = "UPDATE $database SET count = (count+1) WHERE url = '". mysql_real_escape_string($url)."'";

$result = mysql_query($sql) or die("Can not update database.<br />$sql<br />" . mysql_error()); [/quote]
If that still produces an error, you may want to try:[code=php]$sql = "UPDATE $database a SET a.count = (a.count+1) WHERE a.url = '". mysql_real_escape_string($url)."'";
$result = mysql_query($sql) or die("Can not update database.<br />$sql<br />" . mysql_error()); [/code]
Copy linkTweet thisAlerts:
@SheldonauthorJan 14.2007 — Thanks alot It works now!

!
Copy linkTweet thisAlerts:
@bokehJan 14.2007 — Sheldon the reason this happened is because [I]COUNT()[/I] is a MySQL function and you are using it as a column name. These type of words are known as reserved words. If you want to use them in string literal context you can quote the word with backticks so MySQL knows the word is not to be dealt with in function context.[CODE]SELECT COUNT(*)
FROM vampires
WHERE count = 'Dracula'[/CODE]
Copy linkTweet thisAlerts:
@NightShift58Jan 14.2007 — ... or use the "table.field" notation...

Granted, even "table.field" should be backticked if it could be hairy....

Given: table name = count and field name = count, then I would count.count just to be on the safe side.

For example, COUNT is acceptable as a column name. [/quote]"Count" is a function name and, as such, is not a reserved word and may be used as a field name. The problem, if that was the problem, is, I believe, not be the first instance of "count" in "count = (count+1)" but the second one.

Possible solutions, therefore:

SET count = (count + 1) {space as delimiterinside the ()}

SET table.count = (table.count+1)

SET count = (count+ 1)

SET table.count = (table.count + 1)

Obviously, permutations will also work...
Copy linkTweet thisAlerts:
@chazzyJan 14.2007 — Or you use a dbms that throws an error if you use a reserved word ?

Sheldon, is this a dupe thread from the sql forum? And is this what you im'd me about last night?
Copy linkTweet thisAlerts:
@bokehJan 14.2007 — UPDATE portfolio SET count = (count+1) WHERE url = 'http://www.inboxdesign.co.nz' [/QUOTE]The strange thing is that query works fine for me.
×

Success!

Help @Sheldon 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.18,
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,
)...