Jump to content

connecting to multiple databases!


mcerveni

Recommended Posts

Hey guys,

 

I've been connecting to multiple databases, and on my localhost at home it works fine. When I upload everything to the web, it doesn't work at all.

 

When i log in it says: No database selected

 

Code below:

 


<?php include('header.php');

$email = $_GET['email'];
$pass = $_GET['pass'];



$handle = mysql_connect($host,$user,$pwd);
mysql_query("USE $agentcenter_database",$handle);
$query = "SELECT * FROM users WHERE email = '$email' && password = '$pass' ";
$row = mysql_fetch_assoc(mysql_query($query)); 

if($row['email'] == $email && $row['password'] == $pass && $row['activated'] == "yes") {

$empID = $row['empID'];

$_SESSION['asc_logged_in'] = TRUE;



$handle2 = mysql_connect($host2,$user2,$pwd2);
mysql_query("USE $stats",$handle2);


$sql1 = "SELECT * FROM employee_compo WHERE Email = '$email'";
$result1 = mysql_query($sql1) or die(mysql_error());
$row1= mysql_fetch_array($result1);

$agentName = $row1['AgentName'];

$_SESSION['agentName'] = $agentName;
$_SESSION['empID'] = $empID;



echo " <br><br><br>
<h3> Welcome $agentName  </h3>
<a href='home.php'> Continue </a> ";

}

else {

echo "<br><br><br><br> <font color='red'> Your email address or password is wrong.</font> <a href='index.php'> 

Please try again.  </a> "; 

}

?>




 

What doesn't seem to work is the second query. that's where it's giving me  "No database selected"

 

Any idea why?

Link to comment
https://forums.phpfreaks.com/topic/157497-connecting-to-multiple-databases/
Share on other sites

You're not selecting a database after your have connected to the server. This how your code should be:

$handle = mysql_connect($host,$user,$pwd);

 

mysql_select_db('your database name', $handle);

 

mysql_query("USE $agentcenter_database",$handle);

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.