Jump to content

Ajax response problem (php include file prime suspect..)


Recommended Posts

Hello, gonna make this as simple as possible. I apparently receive two different responses. The only difference is that I 'include' a seperate class in the second attempt (which I do not even use) and in the first attempt I leave the 'include' file out. Heres some code.

 

js/ajax.js file

" $.ajax({

type: "GET",

url: "classes/login.php",

data:  'password=kebab',

success: function(resp){

 

                                                alert(resp); // see

 

if(resp == "denied"){

alert('you are not allowed in here!');

}else{

        alert('welcome master!');

}

 

}, 

error: function(e){ 

alert('Error: ');

});

"

 

Then the FIRST attempt 'login.php' file.

"

<?php

require_once 'dbQuery.php';                            // dbQuery.php file does not affect the outcome

//require_once 'an_empty_file.php';                // in the first attempt I have removed this file from being included.

 

$obj = new dbQuery();

 

$sql = "SELECT * FROM users WHERE password='".$password."';";    // the password in the database is infact "pizza", kebab was never found.

$result = $obj->getDbQuery($sql);

 

if (mysql_num_rows($result)) {  // if the password was found then TRUE

                        $echo = "granted";

} else{                                        // password not found, buhu

 

$echo = "denied";

}

echo $echo;

?>

"

 

In this attempt (ther one above). It worked the alert() I had put in the ajax function reads out "denied".

 

Second attempt is exactly the same but I have included the 'an_empty_file.php'. Here is that file.

 

classes/an_empty_file.php

"

<?php

 

?>

"

 

What makes this all weird?

 

In the second attempt with the file included, the alert() ALSO reads out "denied". So both attempts return the exact same string/text "denied". But when arriving to my if function the first attempt reads out "'you are not allowed in here!", while the second one reads out "welcome master!".

 

 

 

I have tried include and require_once. It is weird that my connection class works. but not the other file? Where have I messed up?

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.