Jquery ajax call not working if using connection in include file
<p>I can't figure out why jquery ajax post call not working if I used connection on include php file though I'm getting right response from php. Kindly tell me what's the explanation behind this</p>

<p>This is on my DB file</p>

<pre><code>&lt;?php

$host = "mysql2.000webhost.com"; 
$username = "a212_mt5199";
$password = "secret";
$db = "a211_mydb";

$con = new mysqli ($host, $username, $password, $db);

GLOBAL $con;

if ($con-&gt;connect_error) {
    die ("Error:" . $con-&gt;connect_error);
}

?&gt;  
</code></pre>

<p>This <strong>including the above</strong> is not working</p>

<pre><code>&lt;?php

include("db.php");

// set parameters and execute
$myusername=$_POST['name']; 
$mypassword=$_POST['pwd']; 

// To protect MySQL injection (more detail about MySQL injection)
$myusername = stripslashes($myusername);
$mypassword = stripslashes($mypassword);

$stmt = $con-&gt;prepare("SELECT username, password FROM members WHERE username=? and password=?");
$stmt-&gt;bind_param("ss", $myusername, $mypassword);

$stmt-&gt;execute();
$stmt-&gt;bind_result($username, $password);
$stmt-&gt;store_result();

// Mysql_num_row is counting table row
$count=$stmt-&gt;num_rows;

// If result matched $myusername and $mypassword, table row must be 1 row
if($count==1){
    // Register $myusername, $mypassword and redirect to file "login_success.php"
    session_register("myusername");
    session_register("mypassword"); 
    echo 'true';
    $_SESSION['user_name']= $username;
} else {
    echo "Wrong Username or Password";
}

$stmt-&gt;close();
$con-&gt;close();

?&gt;
</code></pre>

<p>This is working</p>

<pre><code>&lt;?php

$host = "mysql2.000webhost.com"; 
$username = "a212_mt5199";
$password = "secret";
$db = "a211_mydb";

$con = new mysqli ($host, $username, $password, $db);

if ($con-&gt;connect_error) {
    die ("Error:" . $con-&gt;connect_error);
}

// set parameters and execute
$myusername=$_POST['name']; 
$mypassword=$_POST['pwd']; 

// To protect MySQL injection (more detail about MySQL injection)
$myusername = stripslashes($myusername);
$mypassword = stripslashes($mypassword);

$stmt = $con-&gt;prepare("SELECT username, password FROM members WHERE username=? and password=?");
$stmt-&gt;bind_param("ss", $myusername, $mypassword);

$stmt-&gt;execute();
$stmt-&gt;bind_result($username, $password);
$stmt-&gt;store_result();

// Mysql_num_row is counting table row
$count=$stmt-&gt;num_rows;

// If result matched $myusername and $mypassword, table row must be 1 row
if($count==1){
    // Register $myusername, $mypassword and redirect to file "login_success.php"
    session_register("myusername");
    session_register("mypassword"); 
    echo 'true';
    $_SESSION['user_name']= $username;
} else {
    echo "Wrong Username or Password";
}

$stmt-&gt;close();
$con-&gt;close();

?&gt;
</code></pre>