Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/241.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php MySQLi bind_param仅在填写所有字段时有效_Php_Insert_Mysqli - Fatal编程技术网

Php MySQLi bind_param仅在填写所有字段时有效

Php MySQLi bind_param仅在填写所有字段时有效,php,insert,mysqli,Php,Insert,Mysqli,我制作了一个PHP站点,它使用MySQLi的基本功能将HTML5表单提交到我的数据库中。问题是,只有在所有字段都已完成的情况下,它才会插入到数据库中。我如何使它可以让一些字段留空,但让它为其余字段正常工作 //connection statements above $first=$_POST['first']; $last=$_POST['last']; $signed=$_POST['signed']; $cardnumb=$_POST['cardnumb']; $perm=$_POST['

我制作了一个PHP站点,它使用MySQLi的基本功能将HTML5表单提交到我的数据库中。问题是,只有在所有字段都已完成的情况下,它才会插入到数据库中。我如何使它可以让一些字段留空,但让它为其余字段正常工作

//connection statements above

$first=$_POST['first'];
$last=$_POST['last'];
$signed=$_POST['signed'];
$cardnumb=$_POST['cardnumb'];
$perm=$_POST['permcard'];

$stmt = $mysqli->prepare("INSERT INTO information (first_name, last_name, signed, number, permanent) VALUES (?,?,?,?,?)");

$stmt->bind_param("sssss", $first, $last, $signed, $cardnumb, $perm);
$stmt->execute();
$stmt->close();
需要明确的是,如果所有字段都已填写,则此代码工作得非常好。如果某个字段为空,则它不起作用


有没有一种方法可以使用空字段执行此操作?

如果您不填写字段,请执行
$\u POST['varname']返回
null
还是空字符串

如果它是一个空字符串,那么它仍然可以正常工作

如果它的
null
,那么只要数据库中的字段允许
null
,它就应该工作


检查您的表格方案,并确保字段允许为
null

有效!我在没有MySQLi的情况下进行了这个设置,无论是否允许空字段,它似乎都能工作。我想我换成MySQLi后就再也没有检查过。