首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何注册用户

如何注册用户
EN

Stack Overflow用户
提问于 2018-04-30 23:12:28
回答 1查看 75关注 0票数 1

我目前有以下代码:如果该电子邮件已经注册,那么用户将与一条消息促进。但是,如果电子邮件还没有注册,那么他们可以注册。当我运行此代码并注册一个尚未注册的用户时,他们仍然收到用户名已存在的警告。我想可能是支架的问题!

代码语言:javascript
复制
<?php

include ("dbConnect.php");
require 'libPassword.php';

function filter_email_header($email){
  return preg_replace('/[\0\n\r\|\!\/\<\>\^\$\%\*\&]+/','',$email);
}

if(isset($_POST['submit'])){
    $forename = $_POST['forename'];
    $surname = $_POST['surname'];
    $telephone = $_POST['telephone'];
    $address = $_POST['address'];
    $medical_conditions = $_POST['medical_conditions'];
    $dob = $_POST['dob'];
    $email = $_POST['email'];
    $password = $_POST['password'];
    $last_login = date("Y-n-d");




    $dbQuery=$db->prepare("SELECT email FROM customer where email > 0");
            $dbParams = array('email'=>$email);
            $dbQuery->execute($dbParams);
            if ($dbQuery) {
                $message = "username already exists";
                echo "<script type='text/javascript'>alert('$message');</script>";
            }//if
            else{

    $hashPassword = password_hash($pass, PASSWORD_BCRYPT, array("cost" => 12));

      if($dbQuery->rowCount()==0){
          $dbQuery=$db->prepare("INSERT INTO customer (forename, surname, telephone, address, medical_conditions, dob, email, password) VALUES (:forename, :surname, :telephone, :address, :medical_conditions, :dob, :email, :hashPassword)");
            $dbParams = array('forename'=>$forename,'surname'=>$surname, 'telephone'=>$telephone, 'address'=>$address,'medical_conditions'=>$medical_conditions, 'dob'=>$dob, 'email'=>$email, 'hashPassword'=>$hashPassword);
            $dbQuery->execute($dbParams);
            if($dbQuery) {


                header("Location: myProfile.php");
            }//if

        }//if
        else{
                echo('Please fill out all fields marked with *');
            }//else2
            }//else1

if(isset($email)){
  $sender='jess@gymmembership.com';
  $email = filter_email_header($email);
  $headers = "From:". $sender;
  $to      = $email; // Send email to our user
  $subject = 'Signup | Verification'; // Give the email a subject 
  $message = '

Thanks for signing up!
Here is your login details:

------------------------
Your email: '.$email.'
Password: '.$password.'
------------------------

You can now login to your account:


'; // Our message above including the link

$headers = 'From:gymmanagementsystem' . "\r\n"; // Set from headers
//mail($to, $subject, $message, $headers); // Send our email
$sent=mail($to, $subject, $message, $email);
    }}
?>
EN

回答 1

Stack Overflow用户

发布于 2018-04-30 23:31:49

可能是因为您正在检查查询是否已执行,而不是检查是否确实得到了匹配。检查行数是否大于0。

代码语言:javascript
复制
if ($dbQuery) {
    $message = "username already exists";
    echo "<script type='text/javascript'>alert('$message');</script>";
}

我也很确定你可能真的想像这样比较一封电子邮件。

代码语言:javascript
复制
"SELECT email FROM customer where email = :email"

我也不会替换电子邮件中不需要的字符,可能是他们键入了"!“而不是"@“,你的电子邮件将不再有效。我建议通知邮件是无效的,原因是什么。

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/50103374

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档