When this function calls the connect() function I get the returned message from the second function "unable to select database". See asterisks. So I tried a test page to see if my connection strings work and the connection strings work so I don't know how to troubleshoot this? Any suggestions?
thanks,
function doLogin($username, $password)
{
$this->connect();
$this->username = $username;
$this->password = $password;
// check db for user and pass here.
$sql = sprintf("SELECT * FROM user_tbl WHERE UserName = '%s' and Password = '%s' ",
$this->clean($this->username), md5($this->clean($this->password)));
$result = mysql_query($sql, $this->connection);
// If no user/password combo exists return false
if(mysql_affected_rows($this->connection) != 1)
{
$this->disconnect();
return false;
}
else // matching login ok
{
$row = mysql_fetch_assoc($result);
// more secure to regenerate a new id.
session_regenerate_id();
//set session vars up
$_SESSION['LoggedIn'] = true;
$_SESSION['userName'] = $this->username;
}
$this->disconnect();
return true;
}
function connect()
{
$this->connection = mysql_connect($this->db_host, $this->db_user, $this->db_password)
or die("Unable to connect to MySQL");
mysql_select_db($this->db_name, $this->connection) or die("Unable to select DB!"); *********
// Valid connection object? everything ok?
if($this->connection)
{
return true;
}
else return false;
}
$connection= mysql_connect('Xxx.XXX.XX.XX', 'myuser', 'mypassword')or die("Unable to connect to MySQL");
mysql_select_db('mydatabase', $connection) or die("Unable to select DB!");
if ($connection)
echo "hello";
[code=php]