I've made a registration form and used jQuery Form Plugin (ajaxForm) to save the user input to my database. I validated the input fields using javascript in my HTML file, but I checked the email and username in my Php file.
But the problem is, I don't know how to show the echo message in my html file. Like when it echoes "Username is already in use", how can i show it in my html file (as an alert)?
My code is still not complete, I have put mysql_real_escape and encrypted the password using md5. I will do it after I solve my problem. \\
Here is the code in saving the form to my database.
<script>
$(document).ready(function() {
var options = {
resetForm: true,
}
$('form#register').ajaxForm(options);
});
</script>
Here is part of my php file
//username validation
$user_check = mysql_query("SELECT uname FROM se_reg WHERE uname='$uname'");
$do_user_check = mysql_num_rows($user_check);
//email validation
$email_check = mysql_query("SELECT email FROM se_reg WHERE email='$email'");
$do_email_check = mysql_num_rows($email_check);
//error message for username and email
if($do_user_check > 0){
$mess = $json_encode('Username is already in use.');
die("$mess");
}
if($do_email_check > 0){
die("Email is already in use!");
}
database name: se table: se_reg
Maybe this might help:
$('#myForm1').ajaxForm({
resetForm: true,
success: function(responseText, statusText, xhr, $form) {
// responseText is whatever is echoed from server <--
// statusText is going to = success here
// xhr is similar to jqXHR (see jquery.ajax())
// $form is the actual form that was submitted
}
});
keep in mind, all you have to do PHP side is echo
a string
if it's going to be somthing other than a string (aka integer or boolean) be sure to wrap the value in json_encode()
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.