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
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);

Link to comment
Share on other sites

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.