How to switch connection file in php? I have two database whose name is connection.php and connection1.php. when i submit username and password i want to check first database and then if it results empty then need to switch another database. but right now it is connecting only first database and not to second one... I tried to close first but its not working. Plese suggest me any solution...
enter code here
if(!empty($_POST['uname']) && !empty($_POST['pwd']))
{
$flag=0;
if($flag==0)
{
require_once('connection1.php');
$q="select * from user_login where (u_name='".$_POST['uname']."' or eid='".$_POST['uname']."') and password='".$_POST['pwd']."' and status=1";
//echo $q;
$res=mysql_query($q);
$row=mysql_fetch_assoc($res);
}
if(empty($row))
{
$flag=1;
mysql_close($res);
}
if($flag==1)
{
require_once('connection.php');
$q1="select * from user_login where (u_name='".$_POST['uname']."' or eid='".$_POST['uname']."') and password='".$_POST['pwd']."' and status=1";
$res1=mysql_query($q1);
//echo "Database : ".mysql_db_name($res1);
$row1=mysql_fetch_assoc($res1);
}
}
if(!empty($row))
{
$u_id=$row['u_id'];
//header("location:../index.php");
echo "<script>parent.location='Test.php'</script>";
}
else if(!empty($row1))
{
$u_id=$row1['u_id'];
//header("location:../index.php");
// print_r($row1);
echo "<script>parent.location='Test1.php'</script>";
}
else
{
$err = "<font color='red'>Incorrect Login Information</font>";
}
This is connection File:-
enter code here
error_reporting(0);
$app="web";
if($app=="local")
{
define("SITEROOT", "http://".$_SERVER['HTTP_HOST']."/");
define("ABSPATH", "c://xampp/htdocs/ujjwal/");
define("SITEJS", "http://".$_SERVER['HTTP_HOST']."/js2/");
define("SITECSS", "http://".$_SERVER['HTTP_HOST']."/css/");
define("IMAGEDIR", "http://".$_SERVER['HTTP_HOST']."/images/");
define("UPIMAGEDIR", "http://".$_SERVER['HTTP_HOST']."/abcd/abcd/");
define(USR,'root');
define(DB,'xxxx');
define(HST,'localhost');
define(PWD,'');
} enter code here
else
{
define("SITEROOT", "http://".$_SERVER['HTTP_HOST']."/");
define("SITEJS", "http://".$_SERVER['HTTP_HOST']."/js2/");
define("SITECSS", "http://".$_SERVER['HTTP_HOST']."/css/");
define("IMAGEDIR", "http://".$_SERVER['HTTP_HOST']."/images/");
define("UPIMAGEDIR", "http://".$_SERVER['HTTP_HOST']."/zoombox_admin/");
define(USR,'abcdef');
define(DB,'abcd');
define(HST,'111.111.111.111');
define(PWD,'xxx');
}
$con1=mysql_connect(HST,USR,PWD) or die ("connection failed");
$db=mysql_select_db(DB,$con1) or die("db not connected");