0

I want to use two buttons to increment two fields in a database table according to selection.

Field 1: blue
Field 2: yellow

For example:

Blue:   (3)    - Select (+1) - Button 1 (increment the #3)
Yellow: (5)    - Select (+1) - Button 2 (increment the #5)

How is this very simple code possible in php?

I already know how to make the connection.php..

what else?

Details:

say database name is voting: there are two fields, blue and yellow. People can vote for their favorite color: blue or yellow. Click a button or radio in order to increment them values, using a submit or autoupdate (which ever easier)

Norman
  • 79
  • 1
  • 1
  • 7

1 Answers1

3
if ($_GET['input']=="blue") $Field="Field 1"; 
elseif ($_GET['input']=="yellow") $Field="Field 2";
else echo "error";

mysql_query("UPDATE table SET $Field=$Field+1 WHERE Condition");

be a little more specific please.

AbiusX
  • 2,379
  • 20
  • 26
  • say database name is voting: there are two fields, blue and yellow. People can vote for their favorite color: blue or yellow. Click a button or radio in order to increment them values, using a submit or autoupdate (which ever easier) – Norman Mar 14 '11 at 23:46
  • The table structure should not be two fields then, it should be one field named Vote with possible values Blue and Yellow! Then you should insert a vote with the appropriate value. – AbiusX Mar 15 '11 at 00:11
  • Just change your database structure, instead of two fields, put one int field. A value of 1 in the int field means yellow, a value of 2 means blue. If yellow insert one with value 1, if blue insert with 2. – AbiusX Mar 15 '11 at 01:23
  • ok. wait. I dont know if you get me. I want the number to add up. Lets say, 10 people enter and vote. So 5 pick yellow and 5 pick blue. Then if other people want to enter it adds up more numbers... yes? no..? – Norman Mar 15 '11 at 02:01
  • As i said its no good approach, getting COUNT(*) WHERE Vote=1 is much better. – AbiusX Mar 15 '11 at 02:14