0

The problem is, I'm beginner with php and have no idea what the difference between ajax and json. So if someone could clear that up first, that would be great.

Now on to the bigger problem

I found this validation script on this website:
http://www.position-absolute.com/articles/jquery-form-validator-because-form-validation-is-a-mess/

I have it working succesfully EXCEPT for the username validation. It can connect to the external page using this javascript

$(document).ready(function() {	
      $("#reg").validationEngine({
		ajaxName:{
		file:"validateUser.php",
		alertText:"* This user is already taken",
		alertTextOk:"* This user is available",
		alertTextLoad:"* Loading please wait"
		}
	  });
});

In the validateUser.php

<?php
include 'include/dbc.php';
/* RECEIVE VALUE */
$validateValue=$_POST['validateValue'];
$validateId=$_POST['validateId'];
$validateError=$_POST['validateError'];

$rs_duplicate = mysql_query("select count(*) as total from users where user_name='$validateValue' ") or die(mysql_error());
list($total) = mysql_fetch_row($rs_duplicate);

	/* RETURN VALUE */
	$arrayToJs = array();
	$arrayToJs[0] = $validateId;
	$arrayToJs[1] = $validateError;

if ($total > 0){
	$arrayToJs[2] = "true";			// RETURN TRUE
	echo '{"jsonValidateReturn":'.json_encode($arrayToJs).'}';			// RETURN ARRAY WITH success
} else {
	for($x=0;$x<1000000;$x++){
		if($x == 990000){
	$arrayToJs[2] = "false";
	echo '{"jsonValidateReturn":'.json_encode($arrayToJs).'}';		// RETURN ARRAY WITH ERROR
	}	
	}
}
?>

Any help would be much appreciated!

Thanks,
Kedora19

2
Contributors
2
Replies
3
Views
7 Years
Discussion Span
Last Post by Kedora19
0
include 'include/dbc.php';

This line include the database configuration file where the connection with mysql and database is established.

$rs_duplicate = mysql_query("select count(*) as total from [B]users[/B] where user_name='$validateValue' ") or die(mysql_error());

You must have one table in mysql database named users where your user information is stored .
where user_name fields contains the name of user.

after doing this your work is complate.

Good Luck

0

You must have one table in mysql database named users where your user information is stored .
where user_name fields contains the name of user.

I do have a table called users and I have a field called user_name

The original text in the validating file was

<?php

/* RECEIVE VALUE */
$validateValue=$_POST['validateValue'];
$validateId=$_POST['validateId'];
$validateError=$_POST['validateError'];


	/* RETURN VALUE */
	$arrayToJs = array();
	$arrayToJs[0] = $validateId;
	$arrayToJs[1] = $validateError;

if($validateValue =="karnius"){		// validate??
	$arrayToJs[2] = "true";			// RETURN TRUE
	echo '{"jsonValidateReturn":'.json_encode($arrayToJs).'}';			// RETURN ARRAY WITH success
}else{
	for($x=0;$x<1000000;$x++){
		if($x == 990000){
			$arrayToJs[2] = "false";
			echo '{"jsonValidateReturn":'.json_encode($arrayToJs).'}';		// RETURN ARRAY WITH ERROR
		}
	}
	
}

?>

But all it did was if the name karnius was in the field, it said it was available. If you had anything else, the username was not available.

All I did was added the database connecting and checking. It should work but it doesn't.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.