I've got a problem coding an email-address validation on a webpage.
The first step, checking if the input is like [email protected] works. But the second check, if the email already exists in the database, does not seem to work at all.
I'm using the jQuery Validation plugin.
This is my code so far:
Extract from register.php:
<form action="addKunde.php" id="contact-form" method ="post" class="form-horizontal">
<div class="control-group">
<label class="control-label" for="email">E-Mail-Addresse</label>
<div class="controls">
<input type="text" class="input-xlarge" name="email" id="email">
</div>
</div>
<script src="js/jquery.min.js"></script>
<script src="js/jquery.validate.js"></script>
<script src="script.js"></script>
Extract from script.js:
$(document).ready(function(){
$('#contact-form').validate({
rules: {
email: {
maxlength: 100,
required: true,
email: true,
remote: {
url : "check.php",
type : "post"
}
}
},
highlight: function(element) {
$(element).closest('.control-group').removeClass('success').addClass('error');
},
success: function(element) {
$(element).addClass('valid').closest('.control-group').removeClass('error').addClass('success');
}
});
});
Extract from check.php:
<?php
include('mysql.php');
$email = trim(strtolower($_POST['email']));
$email = mysqli_real_escape_string($con, $username);
$result = mysqli_query($con, "SELECT * FROM Kunde WHERE EMail = '$email' LIMIT 1;");
$num = mysqli_num_rows($result);
if($num == 0){
echo "true";
} else {
echo "E-Mail-Adresse schon registriert.";
}
mysqli_close($con);
?>
I've been googling for hours now, following all kinds of different instructions and even trying to implement an own validation method using jQuery-Validation's addMethod.
I hope someone can help me.
Thanks a lot!