EternalSorrow Posted June 21, 2009 Share Posted June 21, 2009 I'm currently trying to implement a login system into my website, and I'm running into some difficulty with adjusting multiple database connections on a single page. I have multiple connections to one database in the banner include of my site, and those are interfering with the session include of the login system which connects with a different database. The error which occurs is that the login system attempts to find the correct table in the wrong database. The only fix I've found is to delete the banner include database connections, but then half of the page would be missing. Is there a way I can end the connection to those banner include databases without also disconnecting the session include database connection? Here's the main page: <? include("include/session.php"); ?> <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> <html> <head> <?php include("ban.php"); ?> <? /* Requested Username error checking */ $req_user = trim($_GET['user']); if(!$req_user || strlen($req_user) == 0 || !eregi("^([0-9a-z])+$", $req_user) || !$database->usernameTaken($req_user)){ die("Username not registered"); } /* Logged in user viewing own account */ if(strcmp($session->username,$req_user) == 0){ echo "<h1>My Account</h1>"; } /* Visitor not viewing own account */ else{ echo "<h1>User Info</h1>"; } /* Display requested user information */ $req_user_info = $database->getUserInfo($req_user); /* Username */ echo "<b>Username: ".$req_user_info['username']."</b><br>"; /* Email */ echo "<b>Email:</b> ".$req_user_info['email']."<br>"; /** * Note: when you add your own fields to the users table * to hold more information, like homepage, location, etc. * they can be easily accessed by the user info array. * * $session->user_info['location']; (for logged in users) * * ..and for this page, * * $req_user_info['location']; (for any user) */ /* If logged in user viewing own account, give link to edit */ if(strcmp($session->username,$req_user) == 0){ echo "<br><a href=\"useredit.php\">Edit Account Information</a><br>"; } /* Link back to main */ echo "<br>Back To [<a href=\"member.php\">Member area</a>]<br>"; ?> <?php include("footer.php"); ?> And here's the banner.php include page with the interfering connections (it's a bit of a mess): <link rel="stylesheet" href="style.css" type="text/css"> <link rel="icon" type="image/gif" href="images/icon.png"> <meta http-equiv="Content-Type" content="text/html;charset=utf-8"> <script src="menu.js" type="text/javascript"></script> <title>InuFiction Archives · comprehensible Inuyasha fanfiction archive</title> </head> <body> <div class="content"> <div class="bg"> <ol class="maps"> <li><a href="contact.php" class="contact"></a> <li><a href="sitemap.php" class="site"></a> <li><a href="affiliates.php" class="affiliate"></a> <li><a href="index.php" class="home"></a> </ol> <div style="padding: 50px 0px 0px 103px; float: left;"> <div class="title"><a href="index.php">InuFiction Archives</a></div> <div class="subtitle">Inuyasha fanfiction database</div> </div> </div> <div class="bg1"> <div class="topnav"> <ol class="search"> <li><a href="about.php">about</a>| <li><a href="categories.php">categories</a>| <li><a href="authorsearch.php">authors</a>| <li><a href="lost.php">lost stories</a>| <li><a href="links.php">links</a>| <li><script type="text/javascript">var addthis_pub="eternalsorrow";</script> <a href="http://www.addthis.com/bookmark.php?v=20" onmouseover="return addthis_open(this, '', '[url]', '[TITLE]')" onmouseout="addthis_close()" onclick="return addthis_sendto()">bookmark</a><script type="text/javascript" src="http://s7.addthis.com/js/200/addthis_widget.js"></script> </ol> <form action="search.php#results" method="POST" class="searchform"> <h3>Search</h3> <input type="hidden" name="category" value="all"> <input type="hidden" name="group" value="all"> <input type="hidden" name="year" value="all"> <input type="text" name="title" class="input"> <input type="submit" name="search" value="" class="go"> </form> </div> <div class="encompass"> <div class="firstnav"> <h4>Site Statistics</h4> <div style="float: left;"><img src="images/sessh.png" alt="pic"></div> <ol class="head"> <li class="even">» 5 awards groups <li>» 29 categories <li class="even"><?php mysql_connect(localhost,user,pw); @mysql_select_db(db) or die( "Unable to select database"); $query="select * from archives "; $result=mysql_query($query); $num=mysql_numrows($result); mysql_close(); echo "» $num total links"; ?> <li><?php mysql_connect(localhost,user,pw); @mysql_select_db(db) or die( "Unable to select database"); $query="SELECT DISTINCT archives.title, author.author FROM archives LEFT JOIN author ON author.id = archives.id "; $result=mysql_query($query); $num=mysql_numrows($result); mysql_close(); echo "» $num unique titles"; ?> <li class="even"><?php mysql_connect(localhost,user,pw); @mysql_select_db(db) or die( "Unable to select database"); $query="select Distinct author from author "; $result=mysql_query($query); $num=mysql_numrows($result); mysql_close(); echo "» $num different authors"; ?> </ol> </div> <div class="secondnav"> <h5>Awards Groups</h5> <div style="float: left;"><img src="images/rin.png" alt="pic"></div> <ol class="head"> <li class="even"><a href="group.php?group=A Single Spark">» A Single Spark</a> <li><a href="group.php?group=Destined Awards">» Destined Awards</a> <li class="even"><a href="group.php?group=Dokuga Awards">» Dokuga Awards</a> <li><a href="group.php?group=Feudal Association">» Feudal Association</a> <li class="even"><a href="group.php?group=Inuyasha Fanguild">» Inuyasha Fanguild</a> </ol> </div> <div class="thirdnav"> <h6>Random Links</h6> <ol class="stats"> <?php mysql_connect(localhost,user,pw); @mysql_select_db(db) or die( "Unable to select database"); $query="SELECT * FROM archives ORDER BY RAND() LIMIT 5 "; $result=mysql_query($query) or die(mysql_error()); while ($row = mysql_fetch_array($result)) { extract($row); echo '<li><a href="'.$url.'" target="_blank">» '.$title.'</a></li>'; } ?> </ol> </div> </div> </div> <div class="bg2"> <div class="left"> Link to comment https://forums.phpfreaks.com/topic/163145-multiple-connection-interference/ Share on other sites More sharing options...
PFMaBiSmAd Posted June 21, 2009 Share Posted June 21, 2009 mysql_connect() returns a link resource. In order for code to use a specific connection when more than one is present, you must use the correct link resource in each mysql_ function that is connection dependent. The default when a link resource is not specified in a mysql_ function is to use the last link created. Link to comment https://forums.phpfreaks.com/topic/163145-multiple-connection-interference/#findComment-860762 Share on other sites More sharing options...
EternalSorrow Posted June 21, 2009 Author Share Posted June 21, 2009 mysql_connect() returns a link resource. In order for code to use a specific connection when more than one is present, you must use the correct link resource in each mysql_ function that is connection dependent. The default when a link resource is not specified in a mysql_ function is to use the last link created. After rummaging through countless pages of manuals, forums, and general websites, I've found I still can't figure out how to implement your suggestion of using connection dependent links. Know of any links with examples relevant to my current situation? And I'm guessing there is no way to 'break,' disconnect, or simply end those first connections so the session would be the only connection seen by the login code? Link to comment https://forums.phpfreaks.com/topic/163145-multiple-connection-interference/#findComment-860793 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.