duanjian4331 2015-11-05 20:46
浏览 22
已采纳

Null X Zero问题

Ok, this is driving me crazy!! Got a MySQL table with an integer field default set to null. Need to update it through a form submission. If form field is blank, set database field to NULL, ELSE set database field to form submission value.

So, in PHP I have: (staging code, still needs to be sanitized)

if($_POST['vendor-product'] != ''){
    $ms2VendorID = $_POST['vendor-product'];
}else{
    $ms2VendorID = '';
}

The problem is that instead of NULL it enters a zero. I've tried several different ways and nothing seems to be working.

Thanks for any help.

  • 写回答

1条回答 默认 最新

  • dongzhao2725 2015-11-05 20:50
    关注

    Why don't you assign NULL (as a string) to your variable in the else statement?

    if($_POST['vendor-product'] != ''){
        $ms2VendorID = $_POST['vendor-product'];
    }else{
        $ms2VendorID = "NULL";
    }
    

    Also, make sure that the field has not the NOT NULL constraint enabled.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥100 有偿,谁有移远的EC200S固件和最新的Qflsh工具。
  • ¥15 找一个QT页面+目标识别(行人检测)的开源项目
  • ¥15 有没有整苹果智能分拣线上图像数据
  • ¥20 有没有人会这个东西的
  • ¥15 cfx考虑调整“enforce system memory limit”参数的设置
  • ¥30 航迹分离,航迹增强,误差分析
  • ¥15 Chrome Manifest扩展引用Ajax-hook库拦截请求失败
  • ¥15 用Ros中的Topic通讯方式控制小乌龟的速度,走矩形;编写订阅器代码
  • ¥15 LLM accuracy检测
  • ¥15 pycharm添加远程解释器报错