Click to See Complete Forum and Search --> : sql query error


printline
09-26-2006, 04:22 AM
Hello!

I am not at all good at sql, so can anyone tell me what this error i get means.......

Warning: mssql_query(): supplied argument is not a valid MS SQL-Link resource in d:\WebHoteller\printline\www\bacon\login.php on line 19

Warning: mssql_fetch_array(): supplied argument is not a valid MS SQL-result resource in d:\WebHoteller\printline\www\bacon\login.php on line 20

Warning: mssql_query(): supplied argument is not a valid MS SQL-Link resource in d:\WebHoteller\printline\www\bacon\login.php on line 30

Warning: mssql_num_rows(): supplied argument is not a valid MS SQL-result resource in d:\WebHoteller\printline\www\bacon\login.php on line 31

My login.php file:

session_start();
$badID = false;
session_register("LoggedIn");
$_SESSION['LoggedIn'] = true;
$cUser = "";
if (isset($_COOKIE['cUserLogin'])) {
$cUser = $_COOKIE['cUserLogin']; }
if(!empty($_POST['key'])) {
$a = $_POST['txtUserID'];
$b = $_POST['txtPassword'];
include("./connopenphp2.inc");
session_register("UserID");
$_SESSION['UserID'] = $a;
$_SESSION['Password'] = $b;
session_register("Password");

$query = "select * from SysParms";
Line 19 $result = mssql_query($query,$conn);
Line 20 $SysParms = mssql_fetch_array($result);
session_register("WebCompanyName");
$_SESSION['WebCompanyName'] = trim($sysparms['WebName']);
session_register("WebName");
$_SESSION['WebName'] = trim($sysparms['WebName']);
session_register("DisplayState");
$_SESSION['DisplayState'] = Trim($sysparms['DisplayState']);

$errormessage = "";
$query = "select * from USERINFO where (UserID = '" . $a . "' and Password = '" . $b . "')";
Line 30 $result = mssql_query($query,$conn);
Line 31 if (mssql_num_rows($result) > 0) {
$userinfo = mssql_fetch_array($result);
if (trim($userinfo['UserActive']) == 'I') {
$errormessage = "Your Login ID has not been activated yet. Please try later.";
$badID = true;
}
if ($userinfo['UserActive'] != 'I') {
if (@$_POST['chkSaveCookie'] == "ON") {
setcookie("cUserLogin", $a);
} else {
setcookie("cUserLogin", "");
};
session_register("SalesRepID");
$_SESSION['SalesRepID'] = $userinfo['SalesRepID'];
session_register("ShowDetails");
$_SESSION['ShowDetails'] = $userinfo['ShowMoveDetails'];
$_SESSION['LoggedIn'] = true;
session_register("CurrentlyLoggedInUser");
$_SESSION['CurrentlyLoggedInUser'] = $userinfo['FirstName'] . " " . $userinfo['LastName'];
@include("search0.php");
return;
}
}
else {
$badID = true;
}
}

chazzy
09-26-2006, 06:55 AM
i don't see where you define $conn.
also, you can't store a database connection in a session (if that's what you were trying.)

printline
09-26-2006, 07:16 AM
I define conn in my connopenphp2.inc file and connect to the database where my code is:

$myServer = "hostname";
$myUser = "usernam";
$myPass = "password";
$myDB = "database_name";

//create an instance of the ADO connection object
$conn = new COM ("ADODB.Connection")
or die("Cannot start ADO");

//define connection string, specify database driver
$connStr = "PROVIDER=SQLOLEDB;SERVER=".$myServer.";UID=".$myUser.";PWD=".$myPass.";DATABASE=".$myDB;
$conn->open($connStr); //Open the connection to the database

My database contains a bunch of customers, and what the file login.php does is checking the customers username and password........

chazzy
09-26-2006, 09:50 AM
change line 19 to


$result = mssql_query($query,$conn) or die(mssql_error());

and that'll tell you what the problem is.

printline
09-26-2006, 10:03 AM
Then i get this error:

Warning: mssql_query(): supplied argument is not a valid MS SQL-Link resource in d:\WebHoteller\printline\www\bacon\login.php on line 19

Fatal error: Call to undefined function mssql_error() in d:\WebHoteller\printline\www\bacon\login.php on line 19

Now what that could mean............???????????????

And perhaps what to do..............????????????

chazzy
09-26-2006, 10:50 AM
sorry. there is no mssql_error() function.

there is a get last message that should provide you some help

so use the function mssql_get_last_message() instead of mssql_error() and see if you can try to interpret the problem.

btw, i'm just reading everything off of php.net