1 Replies - 673 Views - Last Post: 12 October 2009 - 12:56 PM

#1 livium  Icon User is offline

  • D.I.C Addict

Reputation: 0
  • View blog
  • Posts: 519
  • Joined: 21-December 08

Ajax Updater implementation does not work

Posted 12 October 2009 - 12:56 AM

I wanna make a live-error-checking sign up form.
So these are the codes

this is the php file which return echos to the js files (there's no error here, i've posted this so you know what it's all about)

<?php
session_start();
$input_id=$_GET['input_id'];
$input_value=$_GET['input_value'];

$firstname="";
$lastname="";
$nickname="";
$password="";
$rpassword="";
$email="";
$security_code="";

 	switch ($input_id)
	{
	case 'firstname':
		 $nickname=trim($input_value);
		 break;
	case 'lastname':
		 $nickname=trim($input_value);
		 break;
	case 'nickname':
		 $nickname=trim($input_value);
		 break;
	case 'password':
		 $password=trim($input_value);
		 $_SESSION['pass']=$password;
	   if (isset($_SESSION['rpass']))  $rpassword=$_SESSION['rpass'];
		 break;
	case 'rpassword':
		 $rpassword=trim($input_value);
	if(isset($_SESSION['pass']))  $password=$_SESSION['pass'];
		 $_SESSION['rpass']=$rpassword;
		 break;
	case 'email':
		 $email=trim($input_value);
		 break;
	case 'security_code':
		 $security_code=trim($input_value);
		 break;	
	
	}


$server="localhost";
$db_user="root";
$database="cure";
$table="user_info";

mysql_connect($server,$db_user) or die ("Could not connect to mysql because ".mysql_error());
mysql_select_db($database) or die ("Could not select database because ".mysql_error());
	  

$error=0;

if ($nickname=="") {   
			 

echo '<i>Field cannot be null!</i>';

	 $error=1;
			}
			
			
if (strpos($nickname,' ')!=false) {   
			 

echo '<i>Field must not contain spaces! </i>';

	 $error=1;
			 			 
			  }
if ($firstname=="") {   
			 

echo '<i>Field cannot be null!</i>';

	 $error=2;
			}
			
			
if (strpos($firstname,' ')!=false) {   
			 

echo '<i>Field must not contain spaces! </i>';

	 $error=2;
			 			 
			  }			  
			  
			  
if ($lastname=="") {   
			 

echo '<i>Field cannot be null!</i>';

	 $error=3;
			}
			
			
if (strpos($lastname,' ')!=false) {echo '<i>Field must not contain spaces! </i>'; }			  
			  
			  
			
if ($password=="") { echo '<i>Field cannot be null! </i>';}


if (strpos($password,' ')!=false) {  echo '<i>Field must not contain spaces! </i>';}

	  
if (strlen($password)<5) {  
echo '<i>Password has less than 5 characters! </i>';
	  }
if ($password!=$rpassword) {  
echo '<i>Password specified does not match! </i>';

			  }
if (filter_var($email,FILTER_VALIDATE_EMAIL)==false) {  echo '<i>Email specified is not valid! </i>';		  }

  //if (isset($_POST['signup'])) {
  if($_SESSION['security_code'] == $_POST['security_code'] && (!empty($_SESSION['security_code'])) ) {
	 unset($_SESSION['security_code']);
   } else {
	
	  echo '<i> Security code invalid! </i>';
	 
   
	}
  // }

	  mysql_connect($server, $db_user)
	  or die ("Could not connect to mysql because ".mysql_error());
	  
	  mysql_select_db($database)
	  or die ("Could not select database because ".mysql_error());
	  
	  
	   $rs_duplicates = mysql_query("select user_id from user_info where email='$email'");
	$duplicates = mysql_num_rows($rs_duplicates);
	
	//verifica daca mai exista un user cu acelasi email
	if ($duplicates >= 1)
	  {	
				 
echo '<i> User account already exists! </i>';

	
	}
	  
	  // check if the nickname is taken
	  $check = "select user_id from $table2 where nickname = '".$_POST['nickname']."';"; 
	  $qry = mysql_query($check) or die ("Could not match data because ".mysql_error());
	  $num_rows = mysql_num_rows($qry); 
	  if ($num_rows != 0) { 
			
	
	 echo '<i>This Login name is already taken! </i>';
	
	
	  } 
	
	
		  
	 }
	 
?>	 



and this is the js file which I think it doesn't work:

Event.observe(window, 'load', init, false);

function init(){
	 Event.observe('firstname', 'keyup', show_error('firstname'), false);
	 Event.observe('lastname', 'keyup', show_error('lastname'), false);
	 Event.observe('nickname', 'keyup', show_error('nickname'), false);
	 Event.observe('password', 'keyup', show_error('password'), false);
	 Event.observe('rpassword', 'keyup', show_error('rpassword'), false);
	 Event.observe('email', 'keyup', show_error('email'), false);
	 Event.observe('security_code', 'keyup', show_error('security_code'), false);
}



function show_error(divname){
	 var url = 'show_error.php';
	 var pars = 'input_id='+divname+'&input_value='+$F(divname); 
	 var target = divname;
	 var myAjax = new Ajax.Updater(target, url, {method: 'get', parameters: pars});
}




so... this should works like this for example

if a user writes in the text box for nickname a nickname that is already registred then in a text box near the input text it will appear something like : "This Login name is already taken!"
and so on for every field (firstname, lastname...)

I have done this previously with classic ajax tehnics (that with onreadystatechanged) and it worked. But this version does not.
Can you spot the error here?
Please!


Ok. So this is it.

this is the php file which return echos to the js file

CODE

<?php
session_start();
$input_id=$_GET['input_id'];
$input_value=$_GET['input_value'];

$firstname="";
$lastname="";
$nickname="";
$password="";
$rpassword="";
$email="";
$security_code="";

switch ($input_id)
{
case 'firstname':
$nickname=trim($input_value);
break;
case 'lastname':
$nickname=trim($input_value);
break;
case 'nickname':
$nickname=trim($input_value);
break;
case 'password':
$password=trim($input_value);
$_SESSION['pass']=$password;
if (isset($_SESSION['rpass'])) $rpassword=$_SESSION['rpass'];
break;
case 'rpassword':
$rpassword=trim($input_value);
if(isset($_SESSION['pass'])) $password=$_SESSION['pass'];
$_SESSION['rpass']=$rpassword;
break;
case 'email':
$email=trim($input_value);
break;
case 'security_code':
$security_code=trim($input_value);
break;

}


$server="localhost";
$db_user="root";
$database="cure";
$table="user_info";

mysql_connect($server,$db_user) or die ("Could not connect to mysql because ".mysql_error());
mysql_select_db($database) or die ("Could not select database because ".mysql_error());


$error=0;

if ($nickname=="") {


echo '<i>Field cannot be null!</i>';

$error=1;
}


if (strpos($nickname,' ')!=false) {


echo '<i>Field must not contain spaces! </i>';

$error=1;

}
if ($firstname=="") {


echo '<i>Field cannot be null!</i>';

$error=2;
}


if (strpos($firstname,' ')!=false) {


echo '<i>Field must not contain spaces! </i>';

$error=2;

}


if ($lastname=="") {


echo '<i>Field cannot be null!</i>';

$error=3;
}


if (strpos($lastname,' ')!=false) {echo '<i>Field must not contain spaces! </i>'; }



if ($password=="") { echo '<i>Field cannot be null! </i>';}


if (strpos($password,' ')!=false) { echo '<i>Field must not contain spaces! </i>';}


if (strlen($password)<5) {
echo '<i>Password has less than 5 characters! </i>';
}
if ($password!=$rpassword) {
echo '<i>Password specified does not match! </i>';

}
if (filter_var($email,FILTER_VALIDATE_EMAIL)==false) { echo '<i>Email specified is not valid! </i>'; }

//if (isset($_POST['signup'])) {
if($_SESSION['security_code'] == $_POST['security_code'] && (!empty($_SESSION['security_code'])) ) {
unset($_SESSION['security_code']);
} else {

echo '<i> Security code invalid! </i>';


}
// }

mysql_connect($server, $db_user)
or die ("Could not connect to mysql because ".mysql_error());

mysql_select_db($database)
or die ("Could not select database because ".mysql_error());


$rs_duplicates = mysql_query("select user_id from user_info where email='$email'");
$duplicates = mysql_num_rows($rs_duplicates);

//verifica daca mai exista un user cu acelasi email
if ($duplicates >= 1)
{

echo '<i> User account already exists! </i>';


}

// check if the nickname is taken
$check = "select user_id from $table2 where nickname = '".$_POST['nickname']."';";
$qry = mysql_query($check) or die ("Could not match data because ".mysql_error());
$num_rows = mysql_num_rows($qry);
if ($num_rows != 0) {


echo '<i>This Login name is already taken! </i>';


}



}

?>


and this is the js file

CODE


Event.observe(window, 'load', init, false);

function init(){
Event.observe('firstname', 'keyup', show_error('firstname'), false);
Event.observe('lastname', 'keyup', show_error('lastname'), false);
Event.observe('nickname', 'keyup', show_error('nickname'), false);
Event.observe('password', 'keyup', show_error('password'), false);
Event.observe('rpassword', 'keyup', show_error('rpassword'), false);
Event.observe('email', 'keyup', show_error('email'), false);
Event.observe('security_code', 'keyup', show_error('security_code'), false);
}



function show_error(divname){
var url = 'show_error.php';
var pars = 'input_id='+divname+'&input_value='+$F(divname);
var target = divname;
var myAjax = new Ajax.Updater(target, url, {method: 'get', parameters: pars});
}



so... this should works like this for example

if a user writes in the text box for nickname a nickname that is already registred then in a text box near the input text it will appear something like : "This Login name is already taken!"
and so on for every field (firstname, lastname...)

I have done this previously with classic ajax tehnics (that with onreadystatechanged) and it worked. But this version does not.
Can you spot the error here?
Please!

I think there could be 2 potential errors:
1. var pars = 'input_id='+divname+'&input_value='+$F(divname); (is this the correct way to pass parameters?)
2. show_error(divname) (can i put i parameter to a function called by event.observe?)

This post has been edited by livium: 12 October 2009 - 12:58 AM


Is This A Good Question/Topic? 0
  • +

Replies To: Ajax Updater implementation does not work

#2 livium  Icon User is offline

  • D.I.C Addict

Reputation: 0
  • View blog
  • Posts: 519
  • Joined: 21-December 08

Re: Ajax Updater implementation does not work

Posted 12 October 2009 - 12:56 PM

View Postlivium, on 11 Oct, 2009 - 11:56 PM, said:

I wanna make a live-error-checking sign up form.
So these are the codes

this is the php file which return echos to the js files (there's no error here, i've posted this so you know what it's all about)

<?php
session_start();
$input_id=$_GET['input_id'];
$input_value=$_GET['input_value'];

$firstname="";
$lastname="";
$nickname="";
$password="";
$rpassword="";
$email="";
$security_code="";

 	switch ($input_id)
	{
	case 'firstname':
		 $nickname=trim($input_value);
		 break;
	case 'lastname':
		 $nickname=trim($input_value);
		 break;
	case 'nickname':
		 $nickname=trim($input_value);
		 break;
	case 'password':
		 $password=trim($input_value);
		 $_SESSION['pass']=$password;
	   if (isset($_SESSION['rpass']))  $rpassword=$_SESSION['rpass'];
		 break;
	case 'rpassword':
		 $rpassword=trim($input_value);
	if(isset($_SESSION['pass']))  $password=$_SESSION['pass'];
		 $_SESSION['rpass']=$rpassword;
		 break;
	case 'email':
		 $email=trim($input_value);
		 break;
	case 'security_code':
		 $security_code=trim($input_value);
		 break;	
	
	}


$server="localhost";
$db_user="root";
$database="cure";
$table="user_info";

mysql_connect($server,$db_user) or die ("Could not connect to mysql because ".mysql_error());
mysql_select_db($database) or die ("Could not select database because ".mysql_error());
	  

$error=0;

if ($nickname=="") {   
			 

echo '<i>Field cannot be null!</i>';

	 $error=1;
			}
			
			
if (strpos($nickname,' ')!=false) {   
			 

echo '<i>Field must not contain spaces! </i>';

	 $error=1;
			 			 
			  }
if ($firstname=="") {   
			 

echo '<i>Field cannot be null!</i>';

	 $error=2;
			}
			
			
if (strpos($firstname,' ')!=false) {   
			 

echo '<i>Field must not contain spaces! </i>';

	 $error=2;
			 			 
			  }			  
			  
			  
if ($lastname=="") {   
			 

echo '<i>Field cannot be null!</i>';

	 $error=3;
			}
			
			
if (strpos($lastname,' ')!=false) {echo '<i>Field must not contain spaces! </i>'; }			  
			  
			  
			
if ($password=="") { echo '<i>Field cannot be null! </i>';}


if (strpos($password,' ')!=false) {  echo '<i>Field must not contain spaces! </i>';}

	  
if (strlen($password)<5) {  
echo '<i>Password has less than 5 characters! </i>';
	  }
if ($password!=$rpassword) {  
echo '<i>Password specified does not match! </i>';

			  }
if (filter_var($email,FILTER_VALIDATE_EMAIL)==false) {  echo '<i>Email specified is not valid! </i>';		  }

  //if (isset($_POST['signup'])) {
  if($_SESSION['security_code'] == $_POST['security_code'] && (!empty($_SESSION['security_code'])) ) {
	 unset($_SESSION['security_code']);
   } else {
	
	  echo '<i> Security code invalid! </i>';
	 
   
	}
  // }

	  mysql_connect($server, $db_user)
	  or die ("Could not connect to mysql because ".mysql_error());
	  
	  mysql_select_db($database)
	  or die ("Could not select database because ".mysql_error());
	  
	  
	   $rs_duplicates = mysql_query("select user_id from user_info where email='$email'");
	$duplicates = mysql_num_rows($rs_duplicates);
	
	//verifica daca mai exista un user cu acelasi email
	if ($duplicates >= 1)
	  {	
				 
echo '<i> User account already exists! </i>';

	
	}
	  
	  // check if the nickname is taken
	  $check = "select user_id from $table2 where nickname = '".$_POST['nickname']."';"; 
	  $qry = mysql_query($check) or die ("Could not match data because ".mysql_error());
	  $num_rows = mysql_num_rows($qry); 
	  if ($num_rows != 0) { 
			
	
	 echo '<i>This Login name is already taken! </i>';
	
	
	  } 
	
	
		  
	 }
	 
?>	 



and this is the js file which I think it doesn't work:

Event.observe(window, 'load', init, false);

function init(){
	 Event.observe('firstname', 'keyup', show_error('firstname'), false);
	 Event.observe('lastname', 'keyup', show_error('lastname'), false);
	 Event.observe('nickname', 'keyup', show_error('nickname'), false);
	 Event.observe('password', 'keyup', show_error('password'), false);
	 Event.observe('rpassword', 'keyup', show_error('rpassword'), false);
	 Event.observe('email', 'keyup', show_error('email'), false);
	 Event.observe('security_code', 'keyup', show_error('security_code'), false);
}



function show_error(divname){
	 var url = 'show_error.php';
	 var pars = 'input_id='+divname+'&input_value='+$F(divname); 
	 var target = divname;
	 var myAjax = new Ajax.Updater(target, url, {method: 'get', parameters: pars});
}




so... this should works like this for example

if a user writes in the text box for nickname a nickname that is already registred then in a text box near the input text it will appear something like : "This Login name is already taken!"
and so on for every field (firstname, lastname...)

I have done this previously with classic ajax tehnics (that with onreadystatechanged) and it worked. But this version does not.
Can you spot the error here?
Please!


Ok. So this is it.

this is the php file which return echos to the js file

CODE

<?php
session_start();
$input_id=$_GET['input_id'];
$input_value=$_GET['input_value'];

$firstname="";
$lastname="";
$nickname="";
$password="";
$rpassword="";
$email="";
$security_code="";

switch ($input_id)
{
case 'firstname':
$nickname=trim($input_value);
break;
case 'lastname':
$nickname=trim($input_value);
break;
case 'nickname':
$nickname=trim($input_value);
break;
case 'password':
$password=trim($input_value);
$_SESSION['pass']=$password;
if (isset($_SESSION['rpass'])) $rpassword=$_SESSION['rpass'];
break;
case 'rpassword':
$rpassword=trim($input_value);
if(isset($_SESSION['pass'])) $password=$_SESSION['pass'];
$_SESSION['rpass']=$rpassword;
break;
case 'email':
$email=trim($input_value);
break;
case 'security_code':
$security_code=trim($input_value);
break;

}


$server="localhost";
$db_user="root";
$database="cure";
$table="user_info";

mysql_connect($server,$db_user) or die ("Could not connect to mysql because ".mysql_error());
mysql_select_db($database) or die ("Could not select database because ".mysql_error());


$error=0;

if ($nickname=="") {


echo '<i>Field cannot be null!</i>';

$error=1;
}


if (strpos($nickname,' ')!=false) {


echo '<i>Field must not contain spaces! </i>';

$error=1;

}
if ($firstname=="") {


echo '<i>Field cannot be null!</i>';

$error=2;
}


if (strpos($firstname,' ')!=false) {


echo '<i>Field must not contain spaces! </i>';

$error=2;

}


if ($lastname=="") {


echo '<i>Field cannot be null!</i>';

$error=3;
}


if (strpos($lastname,' ')!=false) {echo '<i>Field must not contain spaces! </i>'; }



if ($password=="") { echo '<i>Field cannot be null! </i>';}


if (strpos($password,' ')!=false) { echo '<i>Field must not contain spaces! </i>';}


if (strlen($password)<5) {
echo '<i>Password has less than 5 characters! </i>';
}
if ($password!=$rpassword) {
echo '<i>Password specified does not match! </i>';

}
if (filter_var($email,FILTER_VALIDATE_EMAIL)==false) { echo '<i>Email specified is not valid! </i>'; }

//if (isset($_POST['signup'])) {
if($_SESSION['security_code'] == $_POST['security_code'] && (!empty($_SESSION['security_code'])) ) {
unset($_SESSION['security_code']);
} else {

echo '<i> Security code invalid! </i>';


}
// }

mysql_connect($server, $db_user)
or die ("Could not connect to mysql because ".mysql_error());

mysql_select_db($database)
or die ("Could not select database because ".mysql_error());


$rs_duplicates = mysql_query("select user_id from user_info where email='$email'");
$duplicates = mysql_num_rows($rs_duplicates);

//verifica daca mai exista un user cu acelasi email
if ($duplicates >= 1)
{

echo '<i> User account already exists! </i>';


}

// check if the nickname is taken
$check = "select user_id from $table2 where nickname = '".$_POST['nickname']."';";
$qry = mysql_query($check) or die ("Could not match data because ".mysql_error());
$num_rows = mysql_num_rows($qry);
if ($num_rows != 0) {


echo '<i>This Login name is already taken! </i>';


}



}

?>


and this is the js file

CODE


Event.observe(window, 'load', init, false);

function init(){
Event.observe('firstname', 'keyup', show_error('firstname'), false);
Event.observe('lastname', 'keyup', show_error('lastname'), false);
Event.observe('nickname', 'keyup', show_error('nickname'), false);
Event.observe('password', 'keyup', show_error('password'), false);
Event.observe('rpassword', 'keyup', show_error('rpassword'), false);
Event.observe('email', 'keyup', show_error('email'), false);
Event.observe('security_code', 'keyup', show_error('security_code'), false);
}



function show_error(divname){
var url = 'show_error.php';
var pars = 'input_id='+divname+'&input_value='+$F(divname);
var target = divname;
var myAjax = new Ajax.Updater(target, url, {method: 'get', parameters: pars});
}



so... this should works like this for example

if a user writes in the text box for nickname a nickname that is already registred then in a text box near the input text it will appear something like : "This Login name is already taken!"
and so on for every field (firstname, lastname...)

I have done this previously with classic ajax tehnics (that with onreadystatechanged) and it worked. But this version does not.
Can you spot the error here?
Please!

I think there could be 2 potential errors:
1. var pars = 'input_id='+divname+'&input_value='+$F(divname); (is this the correct way to pass parameters?)
2. show_error(divname) (can i put i parameter to a function called by event.observe?)


C'mon man!
Nobody knows?
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1