$.AJAX JQUERY/PHP login script with strange will of it's own -
hello fellow programmers!
i have annoying problem login script i've built. it's script sends username variable , password variable html form $.ajax (jquery) call check.php file. variables sent keyup function in js. trick there no submit button , user logs in automatically when variables match db. check.php oop multiple methods , when vars match db, php sends json_encode js. want keep script , settings file seperated. when put database settings in check.php file, script works. if try load them externally include @ top, script doesn't work.
js:
$("#wachtwoord, #gebruikersnaam").keyup(function(){ passnum = $("#wachtwoord").val(); usernum = $("#gebruikersnaam").val(); if(passnum.length > 2 && usernum.length > 2) { $.ajax({ type: "post", url: "classes/check.php", datatype: 'json', data: "gebruikersnaam="+usernum+"&wachtwoord="+passnum, success: function(check){ if(check.login == 'true') { stuff! the php:
(other methods , other unnecessary stuff above these lines of code...) public function check(){ if ($_post){ $u = $_post['gebruikersnaam']; $u = strtolower($u); $u = trim($u); $p = $_post['wachtwoord']; mysql_connect(host, user, pw); mysql_select_db(db); $gebruiker = mysql_real_escape_string($u); $wachtwoord = mysql_real_escape_string($p); $query = mysql_query("select * gebruikers gebruikersnaam = '".$gebruiker."' , wachtwoord = '".$wachtwoord."'"); if(mysql_num_rows($query)) { $this->validate(); } } } public function validate(){ $return['login'] = "true"; echo json_encode($return); i find strange script in form works, when include file doesn't return json js. tried multiple things, nothing seems help. when include blank php file, script stops working. thing is, want load configuration data in separate file , don't want my_sql data present in login/check php file.
any thoughts on this?
i'm getting nasty headache because of strange problem.
hope i'm making dumb mistake!
thanks in advance!
rj
i think solved own problem.
some 2 hours wonderful debugging tools , actuallly made progress.
//the infamous include: include ("classes/config.php"); //the dir check.php in: classes!! //error: warning: include() [function.include]: failed opening 'classes/classes/config.php' inclusion the strange thing no php errors shown while turned on, errors streamed jquery script in post/get request. firebug found post request containing php error streamed html php file.
happy dumb mistake, tips , tricks!
hope didn't waste of anyones time!
thx,
rj
Comments
Post a Comment