dongzine3782 2016-02-01 12:57
浏览 19
已采纳

检查电子邮件是唯一的PHP

I am creating a website about music and at the bottom of my website I have a form that has only email submission. I am doing this in order to gather email from the users.

Moreover, I have created a database and in that database I have created a table called emails with only 2 columns:idand email.

I would like to make the emails that I receive unique, because now that I am testing it I can put many emails with the same name. I have tried some coding in order to achieve this but no luck so I will post only the code I have at the moment, so you can help me with what I need to add in that code in order to receive a unique email address.

P.S I will update my database from mysql to mysqli at the end of the project.

Here is my current code:

<?php 
error_reporting(E_ERROR | E_PARSE);
include('../database/db.php');
$email = $_POST['email'];

if($email != "") {
$sql = mysql_query ("INSERT INTO emails (email) VALUES ('$email')");
echo "Thank you for Submitting. Redirecting back to Home Page";
}
?>
  • 写回答

4条回答 默认 最新

  • duanjuan3931 2016-02-01 13:09
    关注
    error_reporting(E_ERROR | E_PARSE);
    include('../database/db.php');
    $email = $_POST['email'];
    if($email != "") {
        $result = mysql_query("SELECT * FROM emails where email='".$email."'");
        $num_rows = mysql_num_rows($result);
        if($num_rows >= 1){
            echo "email exist";
        }else{
            $sql = mysql_query ("INSERT INTO emails (email) VALUES ('$email')");
            echo "Thank you for Submitting. Redirecting back to Home Page";
        }
    }
    

    replace your code with this :)

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(3条)

报告相同问题?

悬赏问题

  • ¥15 在获取boss直聘的聊天的时候只能获取到前40条聊天数据
  • ¥20 关于URL获取的参数,无法执行二选一查询
  • ¥15 液位控制,当液位超过高限时常开触点59闭合,直到液位低于低限时,断开
  • ¥15 marlin编译错误,如何解决?
  • ¥15 有偿四位数,节约算法和扫描算法
  • ¥15 VUE项目怎么运行,系统打不开
  • ¥50 pointpillars等目标检测算法怎么融合注意力机制
  • ¥20 Vs code Mac系统 PHP Debug调试环境配置
  • ¥60 大一项目课,微信小程序
  • ¥15 求视频摘要youtube和ovp数据集