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},
本回答被题主选为最佳回答 , 对您是否有帮助呢?解决 无用评论 打赏 举报