我有一个超级简单的表单,不会将数据输入数据库。当我在输入中输入值时,单击按钮,页面刷新但没有任何内容进入数据库。请帮忙。 页:
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
</head>
<div>
<form action="work/allocate.php" method="post">
<input class="form-control" id="name" name="name" type="text">
<button class="btn btn-primary" type="submit">Assign</button>
</form>
</div>
</html>
PHP:
$name = $mysqli->escape_string($_POST['name']);
$date = date("Ymd");
$sql = "INSERT INTO allocations (name, date) VALUES ('$name','$date')";
if($mysqli->query($sql) === TRUE){
} else {
echo "error" . $sql . "<br>".$mysqli->error;
}
$mysqli->close();
header("Location: {$_SERVER['HTTP_REFERER']}");
exit;
?>