当用户按下b1,b2并且当用户没有按下按钮时保存-1,如何在MySQL 1,0中保存值

时间:2014-04-14 07:32:30

标签: javascript php mysql

我正在尝试制作一个网页,其中我给出两个按钮b1和b2,b1颜色为绿色,b2颜色为红色。我想当用户点击b1然后在MySQL数据库中以绿色值保存值1,当用户按b2然后在MySQL数据库中以红色列值保存0,当用户不按任何按钮然后在数据库中保存-1 。 我怎么能这样做?

我的代码是:

print "<table  width=100% style=table-layout:fixed;>"; 
print "<tr>";
print "<td width=2px style=word-wrap:break-word;;text-align:center;height:40px;>";
print "<form method=post action=check.php>";
print "<input type=hidden value=1 name=red/>";
print "<input type=submit  style=background-color:red/>";
print "</form>";
print "</td>"; 
print "<td width=2px style=word-wrap:break-word;;text-align:center;height:40px;>";
print "<form method=post action=check.php>";
print "<input type=hidden value=0 name=green/>";
print "<input type=submit  style=background-color:green/>";
print "</form>";
print "</td>";
print "</tr>";
print "</table>";

1 个答案:

答案 0 :(得分:0)

我认为你的问题是:

"I have 3 columns in Database, Column GREEN, RED and NOTHING. When user clicks on Button 1 => Update Column GREEN 1 / IF user clicks on Button 2 => Update Column RED 0" If Nothing is pressed update column NOTHING 0

答案:

1. by default in column NOTHING have value 0
2. give button 1 id = btn1, button 2 id = btn2
3. when any button is clicked check for which button user clicked on,
    You can use jQuery [.click()][1] event to do it.
4. when user click on any button, check the button clicked and send [ajax request][2] to php page, 
    where you have mysql state to update your database columns.
5. Ask per button clicked [update your database column][3] and update NOTHING column to 0

http://api.jquery.com/click/
https://api.jquery.com/category/ajax/
http://dev.mysql.com/doc/refman/5.0/en/update.html