-1
我用下面的代码在MySQL中插入数据:数据插入,而字段为空
if ((isset($_POST["MM_insert"])) && ($_POST["MM_insert"] == "form1")) {
$insertSQL=$conn->prepare("INSERT INTO table (ID, COUNTRY, POSTAL_CODE, ADDRESS, PHONE, FAX) VALUES (:a, :b, :c, :d, :e, :f)");
$insertSQL->bindValue(':a', $_POST['ID'], PDO::PARAM_INT);
$insertSQL->bindValue(':b', $_POST['COUNTRY'], PDO::PARAM_STR);
$insertSQL->bindValue(':c', $_POST['POSTAL_CODE'], PDO::PARAM_INT);
$insertSQL->bindValue(':d', $_POST['ADDRESS'], PDO::PARAM_STR);
$insertSQL->bindValue(':e', $_POST['PHONE'], PDO::PARAM_INT);
$insertSQL->bindValue(':f', $_POST['FAX'], PDO::PARAM_INT);
$insertSQL->execute();
}
的问题是,当我不文本字段电话和地址都输入值,他们在我的数据库中设置为0而不是NULL! 我该如何解决这个问题?
这个我第一次看到这样的事情,它完美作品 – Anibel
没有什么说“这工作完美”超过[公认的答案](http://stackoverflow.com/about)。 – NDM
你明白了@NDM – Anibel