PHP-从唯一验证中排除当前电子邮件

时间:2019-05-17 07:23:40

标签: php validation crud

在更新CRUD中的数据时遇到问题,因为我已经定义了用于检查数据库中所有电子邮件的电子邮件验证。

我编写的用于验证电子邮件的代码是:

    $sql = "INSERT INTO reg (first_name, last_name, email, phone, address) VALUES (?, ?, ?, ?, ?)";

     $email = mysqli_real_escape_string($conn, $_POST['email']);

     $user_check_query = "SELECT * FROM reg WHERE email='$email' LIMIT 1";
        $results = mysqli_query($conn, $user_check_query);
        $user = mysqli_fetch_assoc($results);

            if ($user['email'] === $email) {

             $emailerr="Email Already Exists";



             }

        else{

    if($stmt = mysqli_prepare($conn, $sql)){

        mysqli_stmt_bind_param($stmt, "sssss", $param_fname,$param_lname, $param_email,$param_phone, $param_address);


        $param_fname = $first_name;
        $param_lname = $last_name;
        $param_email = $email;
        $param_phone = $phone;
        $param_address = $address;

        if(mysqli_stmt_execute($stmt)){
            header("location:index.php");
            exit();
        } else{
            echo "Something went wrong. Please try again later.";
        }
    }


    mysqli_stmt_close($stmt);
}

我只是根据'ID'从数据库中获取数据,但是当我单击update时,它将检查当前的Email。我只想检查数据库中除当前电子邮件以外的其他电子邮件。

1 个答案:

答案 0 :(得分:0)

您确定此方法有效吗,如果您只是想检查电子邮件是否存在,可以使用count。 如果count> 0,则电子邮件已经存在,则无需

from pyowm import OWM
import matplotlib.pyplot as plt
import numpy as np

API_key = 'XXXXXXXXXXXXXXX'
owm = OWM(API_key)

fc=owm.three_hours_forecast('London,GB')
f = fc.get_forecast()

times=[]
temps=[]
for weather in f:
    date=weather.get_reference_time('date')
    times.append(date)
    t_kelvin=weather.get_temperature()['temp']## get temperature in kelvin
    temps.append(t_kelvin-273.15) ## convert to celsius
    print(date,t_kelvin-273.15) ## just to show what's happening

fig,ax=plt.subplots()
ax.plot(times,temps,label='forecast')

ax.set_ylabel('°C')
ax.set_title('Temperature')
ax.legend()
fig.autofmt_xdate()
plt.show()

您已经在SQL查询中检查了电子邮件,无需再次检查。 希望这会有所帮助