【发布时间】:2013-09-18 13:32:52
【问题描述】:
这对你来说很容易,但我是菜鸟,所以我需要帮助。
这是我的代码,无论出于何种原因 else 语句都没有执行。如果我更改 $variable = NULL 的 NULL 值,它可以工作,但会在我的数据库中输入一个空字符串而不是 NULL 值。谁能帮忙解释一下为什么?
if (isset($_POST['agreeto']))
{
$enter_feedback = "INSERT INTO feedback" . //(initial, surname, country_id, date, friend_score, return_score, service_score, comments)
" VALUES('" . $initial. "', '" . $lastname . "', '" . $country_id . "', NOW(), '" . $friend . "', '" . $return . "', '" . $service . "', '" . $_POST['comments'] . "')";
}else
{
$enter_feedback = "INSERT INTO feedback" . //(initial, surname, country_id, date, friend_score, return_score, service_score, comments)
" VALUES('" . $initial. "', '" . $lastname . "', '" . $country_id . "', NOW(), '" . $friend . "', '" . $return . "', '" . $service . "', " . NULL . ")" or die("couldn't execute my query");
}
【问题讨论】:
-
警告您的代码容易受到 sql 注入攻击。使用参数化查询,这也将解决您的问题。
-
你的栏目允许NULL吗?
-
如果您的列默认值为 NULL - 只是不要在
comments列中插入任何内容,并将其从插入语句中删除 -
你为什么要从你的实际陈述中省略列列表?
-
您将 NULL 作为变量。它应该在 SQL 语句中。删除它周围的点和引号。
". NULL ."到NULL