6 Replies - 586 Views - Last Post: 06 November 2008 - 02:35 PM Rate Topic: -----

#1 Terion  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 16
  • Joined: 29-October 08

connecting to seperate db on one php page

Posted 04 November 2008 - 09:13 AM

I am trying to connect to two different db on one page and keep getting errors that from research tell me I am not connecting
Please someone help, I'm stuck, I keep looking up different ways to do it but nothing is working.
<?php
include("inc/dbconn_openTest.php");

if (empty($_SESSION['AdminLogin']) OR $_SESSION['AdminLogin'] <> 'OK' ){
	header ("Location: LogOut.php");
}

if (isset($_GET['AdminID']) && !empty($_GET['AdminID'])){
	$AdminID = $_GET['AdminID'];
} else {
	header ("Location: LogOut.php");
}

	$query = "SELECT * FROM admin WHERE AdminID='$AdminID'";
	$result = mysql_query ($query);
	$row = mysql_fetch_object ($result);
?>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<title>Work Order System - Administrative Section</title>
<LINK REL="STYLESHEET" HREF="inc/style.css">
</head>

<body bgcolor="#CCCCCC">
<table width="170" border="0" cellpadding="0" cellspacing="0">
	<tr>
		<td align="center"><BR>
		<div class="admin_Title" align="center">Work Order System Admin</div></td>
	</tr>
	<tr>
		<td><BR><HR></td>
	</tr>
	<tr>
		<td><div class="admin_link"><a href="Welcome.php?AdminID=<?php echo $AdminID; ?>" target="mainFrame">Home</a></div></td>
	</tr>
	<tr>
		<td><HR></td>
	</tr>	
<?php
	if ($row->AddWorkOrder == "YES") {
?>	
	<tr>
		<td><div class="admin_link"><a href="WorkOrder.php?AdminID=<?php echo $AdminID; ?>" target="mainFrame">Work Order Form</a></div></td>
	</tr>
	<tr>
		<td><div class="admin_link"><a href="PD_Coupon.php?AdminID=<?php echo $AdminID; ?>" target="mainFrame">Planet Discover Coupon Form</a></div></td>
	</tr>
	<tr>
		<td><div class="admin_link"><a href="PD_TextAd.php?AdminID=<?php echo $AdminID; ?>" target="mainFrame">Planet Discover Yellow Pages/Text Ad Form</a></div></td>
	</tr>
	<tr>
		<td><div class="admin_link"><a href="PD_Enhanced.php?AdminID=<?php echo $AdminID; ?>" target="mainFrame">Planet Discover Enhanced Listing</a></div></td>
	</tr>
	<tr>
		<td><div class="admin_link"><a href="Homescape_Builder.php?AdminID=<?php echo $AdminID; ?>" target="mainFrame">HomeScape Builder Form</a></div></td>
	</tr>	
	<tr>
		<td><div class="admin_link"><a href="Homescape_SpecHome.php?AdminID=<?php echo $AdminID; ?>" target="mainFrame">HomeScape Builder Package Model Information</a></div></td>
	</tr>	
<?php
	}
?>
	<tr>
		<td><HR></td>
	</tr>
<?php	
	if ($row->SearchWorkOrder == "YES") {
?>	
	<tr>
		<td><div class="admin_link"><a href="SearchOrders.php?AdminID=<?php echo $AdminID; ?>" target="mainFrame">Search For Order</a></td>
	</tr>
<?php
	}
?>
	<tr>
		<td><HR></td>
	</tr>
	
	<tr>
		<td align="center">
		<div class="admin_Title" align="center">Art Upload Tools</div></td>
	</tr>
	<tr>
		<td><HR><font color="#CC0000" size="2" face="Verdana, Arial, Helvetica, sans-serif"><strong>Testing Area!! <br> Please use regular ArtUpload Page until I give the word this is "LIVE"</strong></font></td>
	</tr>
	
	<tr>
		<td><div class="admin_link"><a href="../../ArtUpload/admin/AddNewArt.php?AdminID=<?php echo $AdminID; ?>" target="mainFrame">Upload Cust. Artwork</a></div></td>
	</tr>
	<tr>
		<td><div class="admin_link"><a href="../../ArtUpload/admin/AddNewArtManual.php?AdminID=<?php echo $AdminID; ?>" target="mainFrame">Upload New Artwork - Manual</a></div></td>
	</tr>
	
	
	<tr>
		<td><div class="admin_link"><a href="../../ArtUpload/admin/SearchProjects.php?AdminID=<?php echo $AdminID; ?>" target="mainFrame">Search For Art IO</a></td>
	</tr>
	<tr>
		<td><div class="admin_link"><a href="../../ArtUpload/admin/ViewAllArt.php?AdminID=<?php echo $AdminID; ?>" target="mainFrame">View All Projects</a></div></td>
	</tr>
	<tr>
		<td><div class="admin_link"><a href="../../ArtUpload/admin/ViewCompletedArt.php?AdminID=<?php echo $AdminID; ?>" target="mainFrame">View Completed Projects</a>
<?php
   
	$query = "SELECT * FROM admin WHERE AdminID='$AdminID'";
	$result = mysql_query ($query, $con2);
	$row = mysql_fetch_object ($result);
	$sql = "SELECT artwork.ArtID FROM artwork JOIN images ON (artwork.ArtID = images.ArtID) WHERE ";
	$sql .= "artwork.Completed='YES' GROUP BY artwork.ArtID";
	$result = mysql_query ($sql, $con2);
	echo "<span class=\"admin_Count\">(". ceil(mysql_num_rows($result)) .")</span>";
	mysql_close();
?>	
<!--was stuck here on snippet above this line-->
		</div></td>
	</tr>
	<tr>
		<td><HR></td>
	</tr>
	



	
	
		
<?php
	if ($row->ViewNewOrders == "YES") {
?>	
	<tr>
		<td><div class="admin_link"><a href="ViewNewOrders.php?AdminID=<?php echo $AdminID; ?>" target="mainFrame">View New Orders</a>
<?php
	$sql = "SELECT WorkOrderID FROM workorders WHERE Status='New Order'";
	$result = mysql_query ($sql);
	echo "<span class=\"admin_Count\">(". ceil(mysql_num_rows($result)) .")</span>";
?>		
		</div></td>
	</tr>
<?php
	}
	if ($row->ViewNewArt == "YES") {
?>	
	<tr>
		<td><div class="admin_link"><a href="ViewNewArt.php?AdminID=<?php echo $AdminID; ?>" target="mainFrame">View New Art</a>
<?php
	$sql = "SELECT WorkOrderID FROM workorders WHERE Status='New Order' AND FormName='WorkOrder'";
	$result = mysql_query ($sql);
	echo "<span class=\"admin_Count\">(". ceil(mysql_num_rows($result)) .")</span>";
?>		
		</div></td>
	</tr>
<?php
	}
	if ($row->ViewPendingWorkOrders == "YES") {
?>	
	<tr>
		<td><div class="admin_link"><a href="ViewPendingOrders.php?AdminID=<?php echo $AdminID; ?>" target="mainFrame">View Pending Orders</a>
<?php
	$sql = "SELECT WorkOrderID FROM workorders WHERE Status='Pending'";
	$result = mysql_query ($sql);
	echo "<span class=\"admin_Count\">(". ceil(mysql_num_rows($result)) .")</span>";
?>		
		</div></td>
	</tr>
<?php
	}
	if ($row->ViewPendingArtwork == "YES") {
?>	
	<tr>
		<td><div class="admin_link"><a href="ViewPendingArt.php?AdminID=<?php echo $AdminID; ?>" target="mainFrame">View Pending Artwork</a>
<?php
	$sql = "SELECT WorkOrderID FROM workorders WHERE Status='WaitingOnArt'";
	$result = mysql_query ($sql);
	echo "<span class=\"admin_Count\">(". ceil(mysql_num_rows($result)) .")</span>";
?>		
		</div></td>
	</tr>
<?php
	}
	if ($row->ViewCompletedArt == "YES") {
?>	
	<tr>
		<td><div class="admin_link"><a href="ViewCompletedArt.php?AdminID=<?php echo $AdminID; ?>" target="mainFrame">View Completed Artwork</a>
<?php
	$sql = "SELECT WorkOrderID FROM workorders WHERE Status='ArtworkCompleted'";
	$result = mysql_query ($sql);
	echo "<span class=\"admin_Count\">(". ceil(mysql_num_rows($result)) .")</span>";
?>		
		</div></td>
	</tr>
<?php
	}
	if ($row->ViewCompletedWorkOrders == "YES") {
?>	
	<tr>
		<td><div class="admin_link"><a href="ViewCompletedOrders.php?AdminID=<?php echo $AdminID; ?>" target="mainFrame">View Completed Orders</a>
<?php
	$sql = "SELECT WorkOrderID FROM workorders WHERE Status='OrderCompleted'";
	$result = mysql_query ($sql);
	echo "<span class=\"admin_Count\">(". ceil(mysql_num_rows($result)) .")</span>";
?>		
		</div></td>
	</tr>
<?php
	}
	if ($row->ViewAllWorkOrders == "YES") {
?>	
	<tr>
		<td><div class="admin_link"><a href="ViewAllOrders.php?AdminID=<?php echo $AdminID; ?>" target="mainFrame">View All Orders</a>
<?php
	$sql = "SELECT WorkOrderID FROM workorders";
	$result = mysql_query ($sql);
	echo "<span class=\"admin_Count\">(". ceil(mysql_num_rows($result)) .")</span>";
?>		
		</div></td>
	</tr>
<?php
	}
?>
	<tr>
		<td><HR></td>
	</tr>
<?php
	if ($row->AddEditAdmin == "YES") {
?>	
	<tr>
		<td><div class="admin_link"><a href="AddAdmin.php?AdminID=<?php echo $AdminID; ?>" target="mainFrame">Add Admin</a></div></td>
	</tr>
	<tr>
		<td><div class="admin_link"><a href="ViewAdmin.php?AdminID=<?php echo $AdminID; ?>" target="mainFrame">View Admin</a></div></td>
	</tr>
<?php
	}
?>
	<tr>
		<td><div class="admin_link"><a href="ChangePassword.php?AdminID=<?php echo $AdminID; ?>" target="mainFrame">Change My Password</a></div></td>
	</tr>
	<tr>
		<td><HR></td>
	</tr>
	<tr>
		<td><div class="admin_link"><a href="LogOut.php" target="_parent">LogOut</a></div></td>
	</tr>		
</table>
</body>
</html>



Is This A Good Question/Topic? 0
  • +

Replies To: connecting to seperate db on one php page

#2 ghqwerty  Icon User is offline

  • if($spareTime > 0){ $this->writeCode(); }
  • member icon

Reputation: 43
  • View blog
  • Posts: 903
  • Joined: 08-August 08

Re: connecting to seperate db on one php page

Posted 04 November 2008 - 10:15 AM

cant you just make 2 tables ?
Was This Post Helpful? 0
  • +
  • -

#3 Terion  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 16
  • Joined: 29-October 08

Re: connecting to seperate db on one php page

Posted 04 November 2008 - 11:09 AM

View Postghqwerty, on 4 Nov, 2008 - 09:15 AM, said:

cant you just make 2 tables ?

Oh no, I can't, these db have been in place for a while and are big, and serve two purposes, my task is to combine the admin tools so that a dept. can do everything on one site instead of two, and at first I was just leaving everything in place and calling it to the iframe, but part of the menu shows how many pending orders are in there....and so it needs to reference that db, but it doesn't...
I have tried making two conn.
<?php
session_start();

header("Cache-control: private");
header("Expires: " . gmdate("D, d M Y H:i:s", time()) . " GMT"); 

$db_host = "localhost";
$db_user = "root";
$db_pass = "paper";
$db_name = "WorkOrder_DB";


	global $db_host;
	global $db_user;
	global $db_pass;
	global $db_name;
	
$con = mysql_connect($db_host,$db_user,$db_pass) OR die ("Could not connect to the server.");
mysql_select_db($db_name, $con) OR die("Could not connect to the database.");
?>
<?php
session_start();
$db2_host = "localhost";
$db2_user = "root";
$db2_pass = "paper";
$db2_name = "Artupload2";


	global $db2_host;
	global $db2_user;
	global $db2_pass;
	global $db2_name;

$con2 = mysql_connect($db2_host,$db2_user,$db2_pass) OR die ("Could not connect to the server.");
mysql_select_db($db2_name, $con2) OR die("Could not connect to the database.");

?>




Then tried calling it like this when I needed to reference it, but think somewhere my syntax is messed up.
<?php
   
	$query = "SELECT * FROM admin WHERE AdminID='$AdminID'";
	$result = mysql_query ($query, $con2);
	$row = mysql_fetch_object ($result);
	$sql = "SELECT artwork.ArtID FROM artwork JOIN images ON (artwork.ArtID = images.ArtID) WHERE ";
	$sql .= "artwork.Completed='YES' GROUP BY artwork.ArtID";
	$result = mysql_query ($sql, $con2);
	echo "<span class=\"admin_Count\">(". ceil(mysql_num_rows($result)) .")</span>";
	mysql_close();
?>	

Was This Post Helpful? 0
  • +
  • -

#4 PsychoCoder  Icon User is offline

  • Google.Sucks.Init(true);
  • member icon

Reputation: 1639
  • View blog
  • Posts: 19,853
  • Joined: 26-July 07

Re: connecting to seperate db on one php page

Posted 04 November 2008 - 11:23 AM

What is the exact error message you're getting?
Was This Post Helpful? 0
  • +
  • -

#5 ghqwerty  Icon User is offline

  • if($spareTime > 0){ $this->writeCode(); }
  • member icon

Reputation: 43
  • View blog
  • Posts: 903
  • Joined: 08-August 08

Re: connecting to seperate db on one php page

Posted 04 November 2008 - 11:23 AM

2 things with the 2 conns.php

1 is that you have 2 session starts and the other that it will always connect to the second one :)

you would have to have seperate conn.php pages. i think, try with 2 conn.php pages and use msql_close() before you use the second one :)
Was This Post Helpful? 0
  • +
  • -

#6 Terion  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 16
  • Joined: 29-October 08

Re: connecting to seperate db on one php page

Posted 04 November 2008 - 11:47 AM

View Postghqwerty, on 4 Nov, 2008 - 10:23 AM, said:

2 things with the 2 conns.php

1 is that you have 2 session starts and the other that it will always connect to the second one :)

you would have to have seperate conn.php pages. i think, try with 2 conn.php pages and use msql_close() before you use the second one :)


I put the db connections on separate includes
and now I get these errors:
Warning: mysql_query() [function.mysql-query]: Access denied for user 'ODBC'@'localhost' (using password: NO) in C:\Inetpub\wwwroot\WkOrderOnline_V\Menu.php on line 187

Warning: mysql_query() [function.mysql-query]: A link to the server could not be established in C:\Inetpub\wwwroot\WkOrderOnline_V\Menu.php on line 187

Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in C:\Inetpub\wwwroot\WkOrderOnline_V
Was This Post Helpful? 0
  • +
  • -

#7 Terion  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 16
  • Joined: 29-October 08

Re: connecting to seperate db on one php page

Posted 06 November 2008 - 02:35 PM

Didn't see how to mark this as solved but its working now and I have moved on to the next problem (lol) turned out a simple include further down the page worked fine....sometimes I overlook the simple ways.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1