dream890110 2019-05-28 18: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 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 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},
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 对于相关问题的求解与代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 信号傅里叶变换在matlab上遇到的小问题请求帮助
  • ¥15 保护模式-系统加载-段寄存器
  • ¥15 电脑桌面设定一个区域禁止鼠标操作
  • ¥15 求NPF226060磁芯的详细资料