gpt4 book ai didi

javascript - 提交前检查电子邮件无效

转载 作者:行者123 更新时间:2023-11-27 22:56:31 25 4
gpt4 key购买 nike

如何检查电子邮件是否已被占用?我找到了一个脚本,但它仅显示“正在检查..”,如果电子邮件存在,我无法获得确切的结果。下面有代码:

<span id="usernamestatus"></span> 
<input type="text" onblur="checkusername()" id="sign_up_email_input_first" name="email_sign_up" placeholder="E-Mail">

function checkusername() {
var status = document.getElementById("usernamestatus");
var u = document.getElementById("sign_up_email_input_first").value;
if ( u !="") {
status.innerHTML = 'checking...';
var hr = new XMLHttpRequest();
hr.open("POST", "name_check.php", true);
hr.setRequestHeader("Content-type", "application/x-www-form-urlendcoded");
hr.onreadystatechange = function(){
if (hr.readyState == 4 && hr.status ==200) {
status.innerHTML = hr.responseText;
}
}
var v = "name2check="+u;
hr.send(v);
}
}

name_check.php

    if(isset($_POST['sign_up_email_input_first']) && $_POST['sign_up_email_input_first'] != "") {
$username = $_POST['sign_up_email_input_first'];
$sql_name_check = mysql_query("SELECT id FROM users WHERE email = '$username' LIMIT 1");
$uname_check= mysql_num_rows($sql_name_check);
if(strlen($username)<4){
echo "You have invalid e mial adress";
exit();
}
if($uname_check <1){
echo "<strong>". $username. "</strong> Is OK";
exit();
}else{
echo "<strong>" .$username. "</strong> is taken!";
exit();
}
}

最佳答案

在您的 PHP 文件中,替换

$_POST['sign_up_email_input_first']

与:

$_POST['email_sign_up']

您基本上是通过名称而不是 ID 来获取值

关于javascript - 提交前检查电子邮件无效,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37566700/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com