Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

twoodcc

macrumors P6
Original poster
Feb 3, 2005
15,307
26
Right side of wrong
i am trying to add a new column to my database, and using php have a page that updates that new column.

basically what i have is as follows:

"update data set likes = likes+1 where id = '$id'"

and that gives me an error.

but if i run the same command, except on another column, it works. any ideas on what is going on?
 

Cabbit

macrumors 68020
Jan 30, 2006
2,128
1
Scotland
i am trying to add a new column to my database, and using php have a page that updates that new column.

basically what i have is as follows:

"update data set likes = likes+1 where id = '$id'"

and that gives me an error.

but if i run the same command, except on another column, it works. any ideas on what is going on?

If you post the sql error it would be easier to debug.
 

twoodcc

macrumors P6
Original poster
Feb 3, 2005
15,307
26
Right side of wrong
If you post the sql error it would be easier to debug.

well all it says is you have an error in your mysql syntax near "likes = likes +1 where id = '12'"

but if i change likes to another field then it works. it just doesn't work with the new column that i added to the database that already has data in it. i made the column a bigint size 15.
 

firestarter

macrumors 603
Dec 31, 2002
5,506
227
Green and pleasant land
It's probably taken the value 'null' since it's a new column - and complaining 'cos you can't add 1 to null.

Why not update every likes value to 0 before you set out?

Any reason you chose bigint? Any reason you chose not to use 'not null'?
 
Last edited:

twoodcc

macrumors P6
Original poster
Feb 3, 2005
15,307
26
Right side of wrong
It's probably taken the value 'null' since it's a new column - and complaining 'cos you can't add 1 to null.

Why not update every likes value to 0 before you set out?

Any reason you chose bigint? Any reason you chose not to use 'not null'?

well when i first added the column, i put the default 0, and it didn't work. i then deleted it and added it again, without making the default 0, same result. i even put in a 1 for a few records, and the same thing happens.

this is really bothering me that it doesn't work
 

firestarter

macrumors 603
Dec 31, 2002
5,506
227
Green and pleasant land
well when i first added the column, i put the default 0, and it didn't work. i then deleted it and added it again, without making the default 0, same result. i even put in a 1 for a few records, and the same thing happens.

this is really bothering me that it doesn't work

What do you get when you select likes from your table with Id='12'?
 

firestarter

macrumors 603
Dec 31, 2002
5,506
227
Green and pleasant land
That's strange.

How are you testing this... with code, or with an interactive tool?

Just wondering if it's really null, but your test code interprets that as 1.

I can't think of any other good reasons why the update would fail. You haven't put some sort of index on 'like' have you?
 

twoodcc

macrumors P6
Original poster
Feb 3, 2005
15,307
26
Right side of wrong
That's strange.

How are you testing this... with code, or with an interactive tool?

Just wondering if it's really null, but your test code interprets that as 1.

I can't think of any other good reasons why the update would fail. You haven't put some sort of index on 'like' have you?

yeah i can't figure it out either. i kept looking at my code over and over, and don't see why it's failing.

i'm using php for this. basically, i'm using GET with a link. you click the link, it pulls in the info from the database, and updates the 'like' field based on the 'id' from the link.

i do not have an index on like.
 

designguy79

macrumors 6502
Sep 24, 2009
306
2
Michigan
i am trying to add a new column to my database, and using php have a page that updates that new column.

basically what i have is as follows:

"update data set likes = likes+1 where id = '$id'"

and that gives me an error.

but if i run the same command, except on another column, it works. any ideas on what is going on?

Maybe "likes" is a reserved name? Try escaping that, so something like

update data set `likes`=`likes`+1 where id = '$id'

HTH
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.