Norman
Norman

Reputation: 79

Voting Method - Mysql

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)

Upvotes: 0

Views: 301

Answers (1)

AbiusX
AbiusX

Reputation: 2404

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.

Upvotes: 3

Related Questions