用于收集电子邮件的HTML表单不起作用

问题描述 投票:0回答:2

我正在尝试建立电子邮件订阅表单,但是它对我不起作用。单击后,它将重定向到下一页,但数据库中没有数据输入。同样,即使输入值是空白,它也会在“ Continue”之后继续重定向。HTML格式:

<form action="https://www.next-page.com" method="post">
                <input type="text" name="name" placeholder="Your name" id="name"/>
                <input type="text" name="email" placeholder="E-mail" id="email"/>
                <label for="tac">
                    <input type="checkbox" id="tac"/>
                    <span class="concheck">I have read and agree to the <a class="tac">terms and conditions</a></span>
                    <span class="please">Please, agree our terms and conditions</span>
                </label>
                <button class="continue" type="submit" name="submit"><span>+</span> Continue</button>
                <button class="carga"><img src="img/loading.gif"/></button>
                </form>

HTML中的PHP:

<?php
require_once "db.php";
if(isset($_REQUEST['submit']))
{
    mysqli_query($con, "INSERT INTO database (name, email) VALUES ('".$_POST["name"]."', '".$_POST["email"]."')");
    $_POST["name"];
    $_POST["email"];
    header("Location: https://www.next-page.com");
}
?>
php forms http-post
2个回答
0
投票

例如,如果将这两个代码合并到一个文件中,例如index.php,则应从操作中删除https://www.next-page.com<form action="/" method="post">我认为应该可以。而且应该有if(isset($_POST['submit']))


0
投票

操作应针对将要验证的PHP,因此,请创建一个将对其进行验证的新PHP脚本,在现场放置您要使用$ _GET的方法,或者在$ _POST无效的情况下,请使用PHP +名称。在CMD /终端上的php并在此处发布错误,如果您尝试在同一页面上执行此操作,则必须在文件上使用.php,并从中删除操作。

© www.soinside.com 2019 - 2024. All rights reserved.