Skip to main content
Known Participant
September 18, 2009
Question

Problem with my login screen

  • September 18, 2009
  • 1 reply
  • 2232 views

I created a mysql database, a connection in Dreamweaver, and a login page using the tutorials here on the Adobe site.  I thought I had followed everything according to the tutorials, using the "server behaviors" as instructed, but when I try to execute it, I get the following error:

Warning: mysql_select_db() expects parameter 2 to be resource, null given in C:\xampp\htdocs\IOD\loginToIOD.php on line 52

Warning: mysql_query() expects parameter 2 to be resource, null given in C:\xampp\htdocs\IOD\loginToIOD.php on line 57

Here's the code in that area of the page:

<?php
// *** Validate request to login to this site.
if (!isset($_SESSION)) {
  session_start();
}

$loginFormAction = $_SERVER['PHP_SELF'];
if (isset($_GET['accesscheck'])) {
  $_SESSION['PrevUrl'] = $_GET['accesscheck'];
}

if (isset($_POST['username'])) {
  $loginUsername=$_POST['username'];
  $password=$_POST['password'];
  $MM_fldUserAuthorization = "";
  $MM_redirectLoginSuccess = "WOTCPg1.php";
  $MM_redirectLoginFailed = "loginerror.php";
  $MM_redirecttoReferrer = false;
  mysql_select_db($database_LogIn, $LogIn);
 
  $LoginRS__query=sprintf("SELECT UserID, Password FROM authentication WHERE UserID=%s AND Password=%s",
    GetSQLValueString($loginUsername, "text"), GetSQLValueString($password, "text"));
  
  $LoginRS = mysql_query($LoginRS__query, $LogIn) or die(mysql_error());
  $loginFoundUser = mysql_num_rows($LoginRS);
  if ($loginFoundUser) {
     $loginStrGroup = "";
   
    //declare two session variables and assign them
    $_SESSION['MM_Username'] = $loginUsername;
    $_SESSION['MM_UserGroup'] = $loginStrGroup;      

    if (isset($_SESSION['PrevUrl']) && false) {
      $MM_redirectLoginSuccess = $_SESSION['PrevUrl'];
    }
    header("Location: " . $MM_redirectLoginSuccess );
  }
  else {
    header("Location: ". $MM_redirectLoginFailed );
  }
}
?>

The mysql database is named "InfoOnDemand".  It currently contains only 1 table, named "Authenticate", with just one record.  The table fields are:

UserID CHAR 30; Password CHAR 20; CustID CHAR 20 and Status CHAR 10 Default value "in" (that should be "out", but I haven't changed it yet).

This topic has been closed for replies.

1 reply

David_Powers
Inspiring
September 19, 2009

The second parameter passed to both mysql_select_db() and mysql_query() is a reference to the database connection. Judging from the error messages and the code you have posted here, you don't have a MySQL connection defined on that page.

Known Participant
September 19, 2009

I guess I'm a little confused then.  As instructed by the tutorial, I created the database connection using the "Database" panel, and I can view the authentication table's data from there.  Am I supposed to also make that connection on each page that addresse the table?  If so, I don't know how, as I didn't see anything to that effect in the tutorial.  I'm certain that the problem must be in the page, but since its mostly generated code from the "Log In Behaviors" selection, I don't know what to do next.

David_Powers
Inspiring
September 19, 2009

Dreamweaver automatically adds the code to make the connection, when you select the relevant connection in the server behavior dialog box. The first line of code in your page should look something like this:

<?php require_once('../../Connections/connAdmin.php'); ?>