我的页面使用ajax向php脚本发送数据。其中一个变量是:$product_disc。
现在我在脚本中进行了一个小测试,结果表明$product_disc为空。测试如下:
我让我的代码将$test返回给ajax调用过程:
使用Firebug工具,我发现ajax响应中含有:"test":"null"
因此我得出结论:$product_disc的值为null。
现在,在我的脚本中,我正在使用以下代码将数据插入到MySQL数据库中:
查询正在执行,但插入的值为0而不是NULL!只有在明确添加:$product_disc=null; 在MySqli语句之前,插入的值才为NULL。
为什么会这样?NULL和null之间有什么区别?我遵循了stackoverflow中的答案,希望能轻松插入NULL,但随之而来的是这个问题...
谢谢!
PS @stackoverflow团队 - 您的拼写检查字典无法识别stackoverflow这个单词!
if ($product_disc == null)
{$test="null";}
else {$test="not null";}
我让我的代码将$test返回给ajax调用过程:
$return_array['success'] = array ('test' => $test);
使用Firebug工具,我发现ajax响应中含有:"test":"null"
因此我得出结论:$product_disc的值为null。
现在,在我的脚本中,我正在使用以下代码将数据插入到MySQL数据库中:
$stmt = mysqli_prepare($link, "INSERT INTO set_products (id,discount) VALUES (NULL , ?)");
mysqli_stmt_bind_param($stmt, "i", $product_disc);
mysqli_stmt_execute($stmt);
mysqli_stmt_close($stmt);
查询正在执行,但插入的值为0而不是NULL!只有在明确添加:$product_disc=null; 在MySqli语句之前,插入的值才为NULL。
为什么会这样?NULL和null之间有什么区别?我遵循了stackoverflow中的答案,希望能轻松插入NULL,但随之而来的是这个问题...
谢谢!
PS @stackoverflow团队 - 您的拼写检查字典无法识别stackoverflow这个单词!