doujuncuo9339 2017-08-17 19:00
浏览 32
已采纳

如何通过添加从HTML表单收到的数字来更新SQL中的表字段?

How to update table field in SQL by adding to it number received from the HTML form?

Let’s say I have a form:

<form action="">
  <input type="text" name="number" value="1">
   <input type="submit" value="Submit">
</form> 

I have a table in MySQL: TABLE: “test” (ID:1 | Number: 12)

Is it possible to compose sql query which lets me to add number "1" from HTML form to number 12 (ID:1) in my table?

The one way how I understand is possible to do that is to select first number from table “test” and add to it 1, then update the table with the sum what I get. But is it possible to sum 1 and 12 in more easy way?

</div>
  • 写回答

1条回答 默认 最新

  • drpogkqqi536984960 2017-08-17 19:09
    关注

    You can just UPDATE it.

    UPDATE test SET number = number + 1 WHERE id = 1
    

    If the number being added depends on the form input, then get that value and put it in the query (don't forget to use prepared statements):

    UPDATE test SET number = number + :newNumber WHERE id = 1
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥30 win from 窗口最大最小化,控件放大缩小,闪烁问题
  • ¥20 易康econgnition精度验证
  • ¥15 msix packaging tool打包问题
  • ¥28 微信小程序开发页面布局没问题,真机调试的时候页面布局就乱了
  • ¥15 python的qt5界面
  • ¥15 无线电能传输系统MATLAB仿真问题
  • ¥50 如何用脚本实现输入法的热键设置
  • ¥20 我想使用一些网络协议或者部分协议也行,主要想实现类似于traceroute的一定步长内的路由拓扑功能
  • ¥30 深度学习,前后端连接
  • ¥15 孟德尔随机化结果不一致