Results 1 to 7 of 7
  1. #1
    Join Date
    Nov 2005
    Posts
    5

    Question Unanswered: problem searching multiple databases

    I have 2 scripts. accessControl.php controls session information, and formNote.php is a form creation script.

    <? //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');
    ?>

    -----------------------------------------------------------------------

    <? //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>

    ------------------------------------------------------------------------

    when I run formNote.php, i get an error that states:

    Table jmcclure_sessions.topicsTable does not exist. I do not understand why it is not connecting to the jmcclure_MyNotes table????
    Last edited by poisedforflight; 11-15-05 at 23:02.

  2. #2
    Join Date
    Nov 2005
    Posts
    5
    The problem seems to be in accessControl.php b/c if i comment it out, the problem goes away. Just don't know what the problem is.

  3. #3
    Join Date
    Apr 2005
    Location
    Baltimore, MD
    Posts
    297
    For some reason, your code is not selecting the second database. It may be worthwhile to see what is in your include file db.php. The problem may be in there, or how you are using those functions.

    Throw some debug statements in your code to see when you are connected to which database.

  4. #4
    Join Date
    Nov 2005
    Posts
    5
    here is my db.php, and it is connecting fine to the first one, and gives no error until the one i mentioned earlier.

    Code:
    <?php  //db.php
    
    function dbConnect($db=""){
      //global $dbHost, $dbUser, $dbPass;
      
      define('DB_NAME', $db);     // The name of the database
      define('DB_USER', 'user_name');     // Your MySQL username
      define('DB_PASSWORD', 'pass_word'); // ...and password
      define('DB_HOST', 'localhost');     // 99% chance you won't need to change this value
    
      $connection = mysql_connect(DB_HOST,DB_USER,DB_PASSWORD) or die("Could not connect to mysql.");
      $db_handle = mysql_select_db(DB_NAME,$connection) or die("Could not select database.");
    
      return $connection;
    
    }  //end dbConnect()
    
    ?>

  5. #5
    Join Date
    Apr 2005
    Location
    Baltimore, MD
    Posts
    297
    By using define, you are setting the value of a constant. Once that value is set, it cannot be re-set. So, any subsequent time you call that function from within the same script it will always contain the first value passed to it, in this case, it will always connect to the database "jmcclure_sessions". Change the constants to regular variables and you should be set.

  6. #6
    Join Date
    Nov 2005
    Posts
    5

    You sir are the man...

    if i ever get the chance, i'd like to buy you a cold beverage.

  7. #7
    Join Date
    Apr 2005
    Location
    Baltimore, MD
    Posts
    297
    If you ever get the chance to buy me a cold beverage, I will drink it .

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •