PHP / jQuery Retrieve Results

Joined
Oct 28, 2010
Messages
888
Reaction score
115
Hi guys, basically, I am making a register page and I want to know how I can make it so that it validates on the page and tells the user if the email or password they have entered can be used on the database. I've looking into jQuery's ".get" events and things like that but the penny just isn't dropping for me and I am looking for something fast.

If anyone could help me as to where I could possible learn to do this, or if someone can assist me in doing this I'd greatly be appreciative towards them.
 
You can make it so that if an input field of a specific form has its contents changed, you send the value of the input and the input name to a script which returns 1/0 and a specific message. (In JSON possibly.)
With the 1/0, you can... say make the border of the input field red/green and you put the message next to the input field. (Or as a tooltip.)

.change() | jQuery API Documentation
jQuery.post() | jQuery API Documentation
jQuery.parseJSON() | jQuery API Documentation

Ah right, see I was going to make a function so i use the .css() in jquery to change the border-colours or whatever. I still need to be able to for example, enter my email; if it is already registered check the php script, if it returns back true or false then display a result.
Obviously green being it's okay to use, and red for it's invalid.
 
Perhaps create a PHP script "check_exists.php", to which you POST (with jquery) (a) database key(s) & value(s), to which it'll return whether that/those value(s) already exist(s) in the database.

Say you check whether the field "email" with value "[email protected]" and "username" with "test_account" already exist, you can have the php output something like { "email": true, "username": false } (use JSON_encode on an array or whatever), so you know that that email does already exist, and then give that a red border or sth., and the username doesn't already exist, so leave that.
 
html
<input type='text' id='email' onblur='val_umail' required/><!-- i put required so that no need to filter empty field--<
JS
function val_umail(){
var mail = $('#email').val();
$.ajax({
url:"reg.php",
type:"post",
data:{uim:mail},
success:function(out){
if(out==ok){
alert('ok');
}else{
alert('not available');
}
}
});

}
reg.php

$usermail = $_POST['uim'];
/sql query here to get result/user variable $usermail to compare to your db
if($usermail is not exist in database)
{ echo 'ok';}
dont forget to link jquery lib
 
just use the .append() query to add your "error" text if the field is empty or any are.
 
Back