Welcome Guest, Not a member yet? Register   Sign In
Simple ajax call page??
#1

[eluser]Guest[/eluser]
Hi guys,

I've hit a bit of a problem - i'm jquery validation to call a php page to check if an email is in the database.

usally, i would just use this:

validate.js

Code:
username: {
                required: true,
                minlength: 4,
                remote: "../ajax/userchk.php"
            },

then in ajax/userchk.php page:

Code:
<?php
$request = trim(strtolower($_REQUEST['username']));

require_once('../database.php'); // get's database details

    $request = db_input($request);
    $query = db_query("SELECT userID FROM users where username = '" . $request . "'LIMIT 0 , 1 ");
    $found = 0;
    while($suggest = db_fetch_array($query)) {
        $found = $suggest['userID'];
    }
    $valid = 'true';
    if ($found !=0){
        $valid = 'false';
    }
echo $valid;
?>

This works really great on other sites i've done, but i do not know how to do it in codeigniter.

I have tried the same validate.js..

Then created a folder in the root of the site, called "ajax", and made this:

Code:
<?php
    function index()
    {
            $request = trim(strtolower($_REQUEST['username']));
            $query = $this->db->query('SELECT userID FROM users WHERE userName = "'.$request.'"');
            if ($query->num_rows() > 0){
                echo 'true';
            } else {
                echo 'false';
            }    
    }
?>

But it doesnt work :-(

I think the js file is connecting to the php file, as i'm getting an error_log file, so the path is ok. I'm just doing somthing wrong. Error log is this:

Quote:PHP Fatal error: Using $this when not in object context in /home/username/public_html/sitename.com/ajax/userchk.php on line 3


Any help getting this working would be amazing.

Many thanks.


Messages In This Thread
Simple ajax call page?? - by El Forum - 01-13-2010, 02:46 PM
Simple ajax call page?? - by El Forum - 01-13-2010, 03:42 PM
Simple ajax call page?? - by El Forum - 01-13-2010, 03:52 PM
Simple ajax call page?? - by El Forum - 01-14-2010, 04:59 AM
Simple ajax call page?? - by El Forum - 01-14-2010, 05:20 AM



Theme © iAndrew 2016 - Forum software by © MyBB