Problem accessing multiple databases, not at the same time..

This is a discussion on "Problem accessing multiple databases, not at the same time.." within the PHP Forum section. This forum, and the thread "Problem accessing multiple databases, not at the same time.. are both part of the Program Your Website category.



Go Back   Webforumz.com > Main Forums > Program Your Website > PHP Forum

Notices


Reply
 
LinkBack Thread Tools
  #1 (permalink)  
Old Nov 16th, 2005, 06:11
New Member
Join Date: Nov 2005
Age: 28
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Problem accessing multiple databases, not at the same time..

I have 2 scripts. accessControl.php controls session information, and formNote.php is a form creation script. accessControl is an include in formNote.php, and will be in subsequent pages. The way this should work is that accessControl access a database and then verifies membership, then passes control back to formNote. formNote then accesses a seperate database to get some headers for a drop down menu. For some reason it won't access the proper database in formNote. it still tries to connect to the first database.

Any ideas?

Code: Select all
           
<? //formNote.php 
session_start(); 
include 'db.php'; 
include 'accessControl.php'; 
?> 
 
<html> 
<head> 
<title>MyNotes Entry Page</title> 
</head> 
 
<body> 
<form method="post" action="procForm.php"> 
<table> 
<tr> 
<td>Topic Title</td> 
<td><input type="text" name="topicName" size="50" maxlength="50"></td> 
</tr> 
 
<tr> 
<td valign="top">Content</td> 
<td><textarea name="topicBody" rows="10" cols="65"></textarea> 
</tr> 
 
<tr> 
<td>Store Content as</td> 
<td> 
a Subtopic of Page (or as a New Topic) 
 
<? 
dbConnect("jmcclure_MyNotes"); 
$queryA = "SELECT topicId, topicName FROM topicsTable WHERE topicParent = 'NULL'"; 
$result = mysql_query($queryA) or die (error(mysql_error())); 
 
print "<select name='topicParent'>"; 
print "<option value = 'NULL'>New Page</option>"; 
/*while($row = mysql_fetch_assoc($result)){ 
$topId = $row['topicId']; 
$topName = $row['topicName']; 
print "<option value = $topId>$topName</option>"; 
}*/ 
while($row = mysql_fetch_assoc($result)){ 
print "<option value=\"{$row['topicId']}\">{$row['topicName']}</option>\n"; 
} 
?> 
 
</td> 
</tr> 
 
<tr> 
<td><input type="submit" value="Process Page"> 
</tr> 
</table> 
</form> 
 
</body> 
</html>
Code: Select all
               
<? //accessControl.php 
session_start(); 
include_once 'common.php'; 
include_once 'db.php'; 
 
$uid = isset($_POST['uid']) ? $_POST['uid'] : $_SESSION['uid']; 
$pwd = isset($_POST['pwd']) ? $_POST['pwd'] : $_SESSION['pwd']; 
 
//if this is first visit to site, require login 
if(!isset($uid)){ 
?> 
<html> 
<head> 
<title>Please Login for Access</title> 
</head> 
<body> 
<h1>Login Required</h1> 
<p>You must log in to access this area of the site. If you are 
not a registered user, <a href = "signup.php">click here</a> 
to signup for instant access.</p> 
<p><form method ="post" action="<?=$_SERVER['PHP_SELF']?>"> 
User ID: <input type="text" name="uid" size="8"><br> 
Password: <input type="password" name="pwd" size="8"><br> 
<input type="submit" value="Log In"> 
</form></p> 
 
</body> 
</html> 
 
<? 
exit; 
} 
 
$_SESSION['uid'] = $uid; 
$_SESSION['pwd'] = $pwd; 
 
//match uid and pwd to stored username and password 
dbConnect("jmcclure_sessions"); 
$query = "SELECT * FROM user WHERE 
userID = '$uid' AND password = '$pwd'"; 
$result = mysql_query($query); 
if (!$result){ 
error('A database error occured while checking your '. 
'login details.\\nIf this error persists, please '. 
'contact poisedforflight@gmail.com'); 
} //end dbError if 
 
//if uid or pwd not found, reset uid and pwd and try again 
if (mysql_num_rows($result) == 0){ 
unset($_SESSION['uid']); 
unset($_SESSION['pwd']); 
?> 
 
<html> 
<head> 
<title>Access Denied</title> 
</head> 
 
<body> 
<h1>Access Denied</h1> 
<p>Your user ID or password is incorrect, or you are not a 
registered user on this site. To try logging in again, click 
<a href="<?=$_SERVER['PHP_SELF']?>">here</a>. To register for instant 
access, click <a href="signup.php">here</a>.<p> 
 
</body> 
</html> 
<? 
exit; 
} //end uid pwd not found if 
 
$userName = mysql_result($result,0,'fullname'); 
?>

Last edited by poisedforflight; Nov 16th, 2005 at 06:14.
Reply With Quote

  #2 (permalink)  
Old Nov 20th, 2005, 12:09
Reputable Member
Join Date: Sep 2005
Location: Canada, BC
Age: 24
Posts: 239
Thanks: 0
Thanked 0 Times in 0 Posts
Re: Problem accessing multiple databases, not at the same time..

You can access a sepreate database without selecting it sepereately by doing something like
$query = "SELECT * FROM yourdatabase.user WHERE userID = '$uid' AND password = '$pwd'";
Reply With Quote
  #3 (permalink)  
Old Nov 21st, 2005, 13:25
Junior Member
Join Date: Nov 2005
Age: 28
Posts: 10
Thanks: 0
Thanked 0 Times in 0 Posts
Re: Problem accessing multiple databases, not at the same time..

You may try to change database name at mysql_select_db(name, LINK).
You can try it
Reply With Quote
Reply

Tags
problem, accessing, multiple, databases, same, time

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Similar Threads
Thread Thread Starter Forum Replies Last Post
[SOLVED] Problem accessing specific form elements Sagaris JavaScript Forum 4 Sep 23rd, 2007 11:52
problem accessing page number9 Starting Out 4 May 25th, 2007 05:30
Updating multiple records at the same time prob. with script at51178 Classic ASP 11 Feb 1st, 2006 17:56
Date/Time format & multiple selection with listbox problem frmsasp ASP.NET Forum 0 Oct 12th, 2005 10:29


All times are GMT. The time now is 21:02.


Powered by vBulletin®
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.2.0 RC8
© 2003-2008 Webforumz.com : All Rights Reserved

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43