我正在尝试使用php和bootstrap提交电子邮件订阅简报。 var_dump($ _ POST)输出: array(1){' subscribe_submit' => string(0)"" }
这是我的HTML:
<form method="post" action="subscribe.php" class="form-inline" role="form">
<div class="form-group">
<label for="email">Email:</label>
<input type="email" class="form-control" id="email" placeholder="Enter `enter code here`email" required>
</div>
<button type="submit" name="subscribe_submit" class="btn btn-default">Submit</button>
</form>
subscribe.php
<?php
session_start();
include("connect.php");
if(isset($_POST['subscribe_submit']))
{
// Define $email
$email=$_POST['email'];
// Protect from injection
$email = stripslashes($email);
$email = mysqli_real_escape_string($db, $email);
// Check database to see if email is already subscribed
$sql="SELECT id FROM minutes WHERE email='$email'";
$result=$db->query($sql);
$row=$result->fetch_assoc();
if($result->num_rows == 1)
{
echo "You are already subscribed to our minutes.";
}else
{
$sql = "INSERT INTO minutes (email)
VALUES ($email)";
if ($db->query($sql)) {
echo "New record created successfully";
} else {
echo "Error: " . $sql . "<br>" . mysqli_error($db);
}
$db->close();
}
}
?>
我整天都在绞尽脑汁想弄清楚它为什么不起作用。提前谢谢。
答案 0 :(得分:5)
您忘记了最重要的属性name="email"
<input type="email" name="email" class="form-control" id="email"
placeholder="Enter `enter code here`email" required>