dream890110 2019-05-28 10:49
浏览 60
已采纳

AJAX php代码插入NULL而不是输入值到数据库

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?

  • 写回答

1条回答 默认 最新

  • douyan8413 2019-05-28 11:55
    关注

    When you submit the form normally, the form fields will be put in $_POST['toctquantsel]and$_POST['toctquant']`. In your AJAX call, you have

    data: {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},
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
编辑
预览

报告相同问题?

手机看
程序员都在用的中文IT技术交流社区

程序员都在用的中文IT技术交流社区

专业的中文 IT 技术社区,与千万技术人共成长

专业的中文 IT 技术社区,与千万技术人共成长

关注【CSDN】视频号,行业资讯、技术分享精彩不断,直播好礼送不停!

关注【CSDN】视频号,行业资讯、技术分享精彩不断,直播好礼送不停!

客服 返回
顶部