gpt4 book ai didi

php - Bootstrap 表单 $_POST 为空

转载 作者:行者123 更新时间:2023-12-04 16:34:47 27 4
gpt4 key购买 nike

我正在尝试使用 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>

订阅.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();
}
}
?>

我整天都在绞尽脑汁想弄清楚为什么它不起作用。提前致谢。

最佳答案

你忘了最重要的属性 name="email"

<input type="email" name="email" class="form-control" id="email" 
placeholder="Enter `enter code here`email" required>

关于php - Bootstrap 表单 $_POST 为空,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38547369/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com