Could not connect to the database
jeg har script der har virket fint når vi køre med en lille tabelCREATE TABLE `users` (
`user_name` varchar(60) NOT NULL default '',
`password` varchar(15) NOT NULL default '',
`admin` int(1) NOT NULL default '0',
PRIMARY KEY (`user_name`),
KEY `password` (`password`)
) TYPE=MyISAM;
men når vi ligge flere felter på så vil den lige pludselig ikke mere nogen der kan se årsagen..
CREATE TABLE `users2` (
`aut` int(11) NOT NULL auto_increment,
`user_name` varchar(15) NOT NULL default '',
`password` varchar(15) NOT NULL default '',
`email` varchar(60) NOT NULL default '',
`adm` int(1) default '0',
`fornavn` text,
`efternavn` text NOT NULL,
`adresse` text NOT NULL,
`postnr` int(4) NOT NULL default '0',
`bynavn` text NOT NULL,
`baadnavn` text,
`baadtype` text,
`tekst` text,
`pladsnr` int(6) default '0',
`bronr` int(6) NOT NULL default '0',
PRIMARY KEY (`aut`),
UNIQUE KEY `user_name` (`user_name`)
) TYPE=MyISAM AUTO_INCREMENT=57 ;
--
-- Data dump for tabellen `users2`
<?php
include 'db.inc';
function showerror()
{
die("Error " . mysql_errno() . " : " . mysql_error());
}
$appUsername = clean($HTTP_POST_VARS["formUsername"], 60);
$appPassword = clean($HTTP_POST_VARS["formPassword"], 15);
function authenticateUser($connection,
$username,
$password)
{
// Test that the username and password
// are both set and return false if not
if (!isset($username) || !isset($password))
return false;
// Get the two character salt from the username
$salt = substr($username, 0, 2);
// Encrypt the password
//$crypted_password = crypt($password, $salt);
// Formulate the SQL query find the user
$query = "SELECT * FROM users2
WHERE user_name = '$formUsername'
AND password = '$formPassword'");
// Execute the query
$result = @ mysql_query ($query,
$connection)
or showerror( );
// exactly one row? then we have found the user
if (mysql_num_rows($result) != 1)
return false;
else
return true;
}
// Main ----------
session_start( );
$authenticated = false;
// Clean the data collected from the user
$appUsername = clean($HTTP_POST_VARS["formUsername"], 60);
$appPassword = clean($HTTP_POST_VARS["formPassword"], 15);
// Connect to the MySQL server
$connection = @ mysql_connect($hostname,
$username,
$password)
or die("Cannot connect");
if (!mysql_selectdb($databasename,
$connection))
showerror();
$authenticated = authenticateUser($connection,
$appUsername,
$appPassword);
if ($authenticated == true)
{
// Register the customer id
session_register("authenticatedUser");
$authenticatedUser = $appUsername;
// Is the user admin?
# $con = mysql_connect($hostname,$username ,$password);
#mysql_select_db($databasename,$con);
$res = mysql_query("SELECT admin FROM users2
WHERE user_name = '$formUsername'
AND password = '$formPassword'") ;
$number = mysql_num_rows($res);
$row = mysql_fetch_assoc($res);
session_register("adminStatus");
$adminStatus = $row['admin'];
// Register the remote IP address
session_register("loginIpAddress");
$loginIpAddress = $REMOTE_ADDR;
header("Location: ../index.php?pageid=indstillinger");
}
else
{
// The authentication failed
session_register("loginMessage");
$loginMessage =
"Could not connect to the winestore " .
"database as \"$appUsername\"";
header("Location: ../index.php?pageid=login");
}
// Relocate back to the login page
//header("Location: example.9-8.php");
?>
