我試圖驗證輸入的電子郵件地址是不是已經在我的數據基礎。我有以下代碼:在驗證數據庫中值的心不是已經
繼承人在我的HTML我的形式
<form action="signup.php" method="post" onsubmit="return validateForm(this);">
<input type="text" name="First_name" placeholder="First Name" required pattern="[A-Za-z].{2,}" maxlength="20" oninvalid="this.setCustomValidity('Must be between 2 and 20 characters long and no numbers!')"/>
<input type="text" name="Last_name" placeholder="Last Name" required pattern="[A-Za-z']..{2,}" maxlength="20" oninvalid="this.setCustomValidity('Must be between 2 and 20 characters long! and no numbers')"/>
<input type="email" pattern="[a-z0-9._%+-][email protected][a-z0-9.-]+\.[a-z]{2,4}$" name="Email" required placeholder="Email Address" maxlength="30" oninvalid="this.setCustomValidity('Must be a validate Email Address!')"/>
<input type="email" pattern="[a-z0-9._%+-][email protected][a-z0-9.-]+\.[a-z]{2,4}$" name="Email2" required placeholder="Comfirm Email Address" maxlength="30" oninvalid="this.setCustomValidity('Must be a validate Email Address!')"/>
<input type="password" name="Password" placeholder="Password" required maxlength="20" required pattern=".{6,}" oninvalid="this.setCustomValidity('Must be between 6 and 20 characters long!')"/>
<input type="Submit" value="Submit" name="Submit" id="Submit"/>
</form>
我的繼承人在HTML頂部的jQuery:
<script type="text/javascript" src="js/jquery.js"></script>
<script type="text/javascript">
$(document).ready(function() {
//result texts
var email_error = 'Emails do not match!';
alert("Hi");
//when button is clicked
$('#Submit').click(function(){
//run the character number check
if($('#Email').val() != $('#Email2').val()){
//if it's bellow the minimum show characters_error text '
$('#emailValidate').html(email_error);
}else{
//else show the cheking_text and run the function to check
check_availability();
}
});
});
//function to check username availability
function check_availability(){
//get the username
var Email = $('#Email').val();
//use ajax to run the check
$.post("checkmail.php", { Email: Email },
function(result){
//if the result is 1
if(result == 1){
//show that the username is available
$('#emailValidate').html(Email + ' is Available');
}else{
//show that the username is NOT available
$('#emailValidate').html(Email + ' is not Available');
}
});
}
</script>
這是我的PHP文件
<?php
$servername = "localhost";
$username = "root";
$password = "root";
$DB = "database";
// Create connection
$conn = mysqli_connect($servername, $username, $password, $DB);
// Check connection
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
$sql = "SELECT Email FROM Users WHERE Email = '".$_POST['Email']."'";
$select = mysqli_query($conn, $sql);
$row = mysqli_num_rows($select);
if($row > 0)) {
echo 1;
}else
echo 0;
?>
現在,當我點擊提交沒有發生邏輯。由於某種原因,它沒有檢測到提交和不評估。我使用提交作爲ID,它不是拿起它。我錯誤地處理了這個問題嗎?
我沒有看到'validateForm()'函數。你也沒有身份證。 –
由於'Email'是一個文本字段,你必須使用像引號:'WHERE電子郵件=「;',注意到你的代碼也vurnable SQL注入 – Cyclonecode
$。員額「」 [電子郵件‘$ _ POST’。」「 (「checkmail.php」?{電子郵件:電子郵件}, 哪裏是電子郵件 – jrath