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]
<? //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]
<? //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 [email protected]’);
} //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’);
?>