通讯订阅表显示文本

时间:2019-02-16 08:22:03

标签: php forms form-submit newsletter onsubmit

我的通讯表格需要帮助

  1. 如何确保表格不能为空
  2. 避免在数据中添加来自用户的相同电子邮件
  3. 单击“订阅”按钮时,显示一条简单的消息,谢谢您的订阅,而不是直接访问action.php。

form.php

<?php
include 'connect.php';

?>
<html>
<head>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
</head>
<body>
<h3>Subscribe to our Mailing list</h3>
<form action="add.php" method="post" id="embed-form" >
Your Name..
<input type="text" name="name" id="name" placeholder="Your Name"><br>
Your Email..
<input type="email" name="email" id="email" placeholder="Your Email"><br>
<input type="submit" name="submit" id="submi" value="Subscribe">
<span id="success-message" class="email-success"</span>
</form>

</body>

</html>

Connect.php

<?php
 $conn=mysqli_connect("localhost","root","","subscriber");

 //Check Connection
 if(mysqli_connect_errno()){
     echo "Failed to connect to MySqli";
     mysqli_connect_errno();
 }
?>

add.php

<?php
include 'connect.php';

if(isset($_POST['name'])&& isset($_POST['email'])){
    $n=$_POST['name'];
    $e=$_POST['email'];
    $s=$_POST['submit'];

    $query=("INSERT INTO newsub (name, email) VALUES ('$n','$e')");
    $result=mysqli_query($conn,$query);

    $result=mysqli_query($conn,$query);

    echo "Thank you for your subscription";
}   

?>

0 个答案:

没有答案