I am trying to insert 2 values interchangeably to my database - my Select element with name=toctquantsel
and my Input element with name=toctquant
. When my Select element is hidden, the value of my Input will be inserted to the database, and vise versa. I was able to achieve with my php code alone, however when doing this with AJAX, I get the error message, "Uncaught mysqli_sql_exception: Column 'toctquant' cannot be null
". Again, I did not get this error when not using AJAX. How do I fix this so I can insert my values to the database without having to change my database columns to NULL?
AJAX php代码插入NULL而不是输入值到数据库
- 写回答
- 好问题 0 提建议
- 追加酬金
- 关注问题
- 邀请回答
-
1条回答 默认 最新
- douyan8413 2019-05-28 19:55关注
When you submit the form normally, the form fields will be put in
$_POST['toctquantsel
]and
$_POST['toctquant']`. In your AJAX call, you havedata: {selectValueBox: selectValue, inputValueBox: inputValue},
When you use AJAX, the parameter names sent to PHP come from the
data:
object, not the names of the form fields. So these fields will be in$_POST['selectValueBox']
and$_POST['inputValueBox']
. To make your AJAX code work with the same PHP code on the server, you need to change that to:data: {toctquantsel: selectValue, toctquant: inputValue},
本回答被题主选为最佳回答 , 对您是否有帮助呢?解决 无用评论 打赏 举报
悬赏问题
- ¥15 msix packaging tool打包问题
- ¥28 微信小程序开发页面布局没问题,真机调试的时候页面布局就乱了
- ¥15 python的qt5界面
- ¥15 无线电能传输系统MATLAB仿真问题
- ¥50 如何用脚本实现输入法的热键设置
- ¥20 我想使用一些网络协议或者部分协议也行,主要想实现类似于traceroute的一定步长内的路由拓扑功能
- ¥30 深度学习,前后端连接
- ¥15 孟德尔随机化结果不一致
- ¥15 apm2.8飞控罗盘bad health,加速度计校准失败
- ¥15 求解O-S方程的特征值问题给出边界层布拉休斯平行流的中性曲线