$query = "INSERT INTO api_fails (file, code, url, date) VALUES (?, ?, ?, ".time().")";
$stmt = $mysqli->stmt_init();
if(!$stmt->prepare($query)) {
echo("Failed to prepare statement.<br />\n");
} else {
$file = $_GET['f'];
$code = $_GET['c'];
$url = $_GET['u'];
$stmt->bind_param("sis", $file, $code, $url);
if($stmt->execute()) {
echo("Inserted.<br />\n");
}else {
echo("Didn't insert.<br />\n");
}
}
我发现如果未设置以下任何变量,则插入失败...
$file = $_GET['f'];
$code = $_GET['c'];
$url = $_GET['u'];
如何设置插入,以便在未设置变量的情况下只插入该字段?
答案 0 :(得分:1)
如果未设置这些变量,只需将空值分配:
$file = (isset($_GET['f'])) ? $_GET['f'] : '' ;
$code = (isset($_GET['c'])) ? $_GET['c'] : '' ;
$url = (isset($_GET['u'])) ? $_GET['u'] : '' ;