Javascript 如何在MySQL 1,0中保存值,当用户按下b1、b2时,以及当用户没有按下按钮时如何保存-1

Javascript 如何在MySQL 1,0中保存值,当用户按下b1、b2时,以及当用户没有按下按钮时如何保存-1,javascript,php,mysql,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 st

我正在尝试制作一个网页,其中我给出了两个按钮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>";
print”“;
打印“”;
打印“”;
打印“”;
打印“”;
打印“”;
打印“”;
打印“”;
打印“”;
打印“”;
打印“”;
打印“”;
打印“”;
打印“”;
打印“”;
打印“”;

我想你的问题是:

“我在数据库中有3列,绿色列、红色列和空白列。当用户单击按钮1=>Update Column GREEN 1/如果用户单击按钮2=>Update Column RED 0”如果未按下,则更新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

您如何知道用户何时“未按下”或“尚未按下”?先生,由于复选框中有一个单击事件,如果选中保存1,如果未选中保存0,我将尝试捕获按钮单击事件。但我不知道如果两个按钮都未单击,则通过javascript我希望在数据库中插入-1尝试使用AJAX请求onclick/onchange事件