Jump to content

[SOLVED] Problems with update and set


jber

Recommended Posts

 

Hello!

 

I´m making a  poll using PHP and MySQL. So i have a table with the next fields

Idpoll which is INT and is the id of the poll

Question , TEXT

Answer1, TEXT

Answer2, TEXT

Answer3, TEXT

Value1, INT

Value2, INT

Value3, INT

Total, INT

 

Each time an option is selected, Value has to be incremented (value=value +1) so if i press Answer1, Value1=Value+1.

So the proposed query will be :

(after initialising a poll of course)

UPDATE polls SET Value1 = Value1+1;

 

but when i look at Value1's value it has not been changed at all!

But, more strange, if I do UPDATE polls SET Idpoll=Idpoll+1 IT DOES WORK.

 

I don´t know what´s goin on, but something kinda strange happens (doingo the same query in the MySQL console in WAMP server does not work also, it says that the quey is OK , Rows matched : 1 Changed : 0 Warnings :0

 

¿Can you please help me?

Thanks in advance

Link to comment
https://forums.phpfreaks.com/topic/62461-solved-problems-with-update-and-set/
Share on other sites

SOLUTION: Sorry, i forgot to add it. The problem was if you don´t initialise some variables, the system takes them as NULL. So if you want to do value1 = value1 +1 , it is not equal as value 1 = NULL + 1 = 1. You have to initialise every numeric variable as 0 (or the value you want)

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.