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
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)

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.