Welcome Guest, Not a member yet? Register   Sign In
i cant retrieve the query result
#1

[eluser]mistress_shiira[/eluser]
good eve guys.im doing a simple validation exercise.for this purpose,i have created a databse called dev and a table i named users that contains the fields ID and username.

I have a form that contains a text input for username,password,email and country and a button beside username that checks whether the input does not exist yet in my users table...
Basically,what i would do is make this thing work using codeigniter+xajax.

i have to check whether the username typed already exists or not and then output a message near the username textbox stating whether the username exists or not.
this is how i did this:
Quote:<?php

class Validate extends Controller {
function index() {

$this->load->library('validation');
$this->load->helper(array('form','url'));

//set validation rules
$rules['username'] = 'required|trim';
$rules['password'] = 'required|trim|min_length[6]|max_length[10]';
$rules['email'] = 'required|trim|valid_email';
$rules['country'] = 'required|trim';
$this->validation->set_rules($rules);
//set validation fields
$fields['username'] = 'username';
$fields['password'] = 'password';
$fields['email'] = 'email address';
$fields['country'] = 'country';
$this->validation->set_fields($fields);


function test_function($name) {
$objResponse = new xajaxResponse();
$objResponse->assign("hello","innerHTML",$name);
return $objResponse;
}
function name_check($name){
/*$sql = $this->db->query('select * from users where username=$name');
foreach($query->result() as $row){
$user = $row->username;

$objResponse = new xajaxResponse();
$objResponse->assign("working","innerHTML",$row->ID);
return $objResponse;
}*/
if($name == "hello"){
$objResponse = new xajaxResponse();
sleep(2);
$objResponse->assign("hello","innerHTML",$name);
}else{
$objResponse = new xajaxResponse();
sleep(2);
$objResponse->assign("hello","innerHTML",$name);
}
return $objResponse;
}
$this->load->library('xajax');

$this->xajax->registerFunction("test_function");
$this->xajax->registerFunction("name_check");

$this->xajax->processRequest();

$template['xajax_js'] = $this->xajax->getjavascript('../../');
$this->load->view('failed', $template);
}
}
?>
Another thing,how will you disable the submit button while the information has not been submitted yet or the username has not been checked and not all fields have been filled up?
#2

[eluser]mistress_shiira[/eluser]
dont bother replying to this post.i have already found a solution to my problem.
i have used $ci_instance




Theme © iAndrew 2016 - Forum software by © MyBB