第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號(hào)安全,請(qǐng)及時(shí)綁定郵箱和手機(jī)立即綁定
已解決430363個(gè)問題,去搜搜看,總會(huì)有你想問的

如何查看郵箱是否已被使用

如何查看郵箱是否已被使用

PHP
侃侃無極 2023-10-15 16:00:18
我使用 PHP 進(jìn)行了表單驗(yàn)證。如果發(fā)生錯(cuò)誤,錯(cuò)誤消息將顯示在每個(gè)輸入列周圍。我想檢查一下這個(gè)郵箱是否被使用過。因此,我使用錯(cuò)誤代碼來定義是否使用輸入電子郵件地址,然后顯示“電子郵件已被使用”的錯(cuò)誤消息。然而,結(jié)果變成了我輸入的任何內(nèi)容,它只顯示“電子郵件已被使用”。有人可以幫我解決這個(gè)問題嗎?謝謝!<?php  require_once('./conn.php');  $errorMsgs = array('nickname'=>'', 'email'=>'', 'password'=>'');    if(isset($_POST['submit'])) {    if(empty($_POST['nickname'])) {      $errorMsgs['nickname'] = "Please enter your nickname";    }    $email = $_POST['email'];    $password = $_POST['password'];        // checking the email is valid or empty    if(empty($_POST['email'])) {      $errorMsgs['email'] = "Please enter your email";    } else {      if(!filter_var($email, FILTER_VALIDATE_EMAIL)) {        $errorMsgs['email'] = "Please enter a valid email";      }    }    $errorCode = $conn->errno;    if($errorCode === 1062) {      $errorMsgs['email'] = "The email has been used";    }    // checking the password is valid or empty    if(empty($_POST['password'])) {      $errorMsgs['password'] = "Please enter your password";    } else {      if(!preg_match('/\w{8,}/', $password)) {        $errorMsgs['password'] = "Please enter at least 8 characters";      }    }        if(!array_filter($errorMsgs)) {    $sql = sprintf("INSERT INTO member (nickname, email, password) values ('%s', '%s', '%s')", $_POST['nickname'], $_POST['email'],$_POST['password']);    $result = $conn->query($sql);    if($result) {      header("Location: index.php");    }  }}?>
查看完整描述

1 回答

?
慕蓋茨4494581

TA貢獻(xiàn)1850條經(jīng)驗(yàn) 獲得超11個(gè)贊

您必須檢查該電子郵件是否存在于您的用戶表中。像這樣的東西。


<?php

  require_once('./conn.php');

  $errorMsgs = array('nickname'=>'', 'email'=>'', 'password'=>'');

  

  if(isset($_POST['submit'])) {

    if(empty($_POST['nickname'])) {

      $errorMsgs['nickname'] = "Please enter your nickname";

    }


    $email = $_POST['email'];

    $password = $_POST['password'];

    

    // checking the email is valid or empty

    if(empty($_POST['email'])) {

      $errorMsgs['email'] = "Please enter your email";

    } else {

      if(!filter_var($email, FILTER_VALIDATE_EMAIL)) {

        $errorMsgs['email'] = "Please enter a valid email";

      }

      else{

          //you should use sql parameter binding

     $email = $_POST['email'];

    $checkDuplicate= $conn->query("SELECT email FROM user_table where email = '$email'");

    if(!empty($checkDuplicate)) {

      $errorMsgs['email'] = "The email has been used";

    }

      }

    }

     


    // checking the password is valid or empty

    if(empty($_POST['password'])) {

      $errorMsgs['password'] = "Please enter your password";

    } else {

      if(!preg_match('/\w{8,}/', $password)) {

        $errorMsgs['password'] = "Please enter at least 8 characters";

      }

    }

    

    if(empty($errorMsgs)) { //you need to check if there's any error

    $sql = sprintf("INSERT INTO member (nickname, email, password) values ('%s', '%s', '%s')", $_POST['nickname'], $_POST['email'],$_POST['password']);


    $result = $conn->query($sql);

    if($result) {

      header("Location: index.php");

    }

  }

}

?>


查看完整回答
反對(duì) 回復(fù) 2023-10-15
  • 1 回答
  • 0 關(guān)注
  • 142 瀏覽

添加回答

舉報(bào)

0/150
提交
取消
微信客服

購課補(bǔ)貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動(dòng)學(xué)習(xí)伙伴

公眾號(hào)

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號(hào)