Hey peoples,
I am experimenting creating a web application which connects to a database to check a username/password.
But when I try the app I get HTTP 500 (Internal Server Error). The project compiles successfully in BCB5.
I have never used database components in BCB before, but a few days ago I managed to connect to a database using a TDBGrid thing, now I want to get it to work with a web application.
Anyway, here's the essential code (i think):
And here's the two database components I have:
Is this the correct way to connect to a database in BCB? If not, could you please tell me the best way to do this?
Thanks in advance!
I am experimenting creating a web application which connects to a database to check a username/password.
But when I try the app I get HTTP 500 (Internal Server Error). The project compiles successfully in BCB5.
I have never used database components in BCB before, but a few days ago I managed to connect to a database using a TDBGrid thing, now I want to get it to work with a web application.
Anyway, here's the essential code (i think):
Code:
void __fastcall TWebModule1::WebModule1waLoginAction(TObject *Sender,
TWebRequest *Request, TWebResponse *Response, bool &Handled)
{
if (Request->ContentFields->Values["UserName"] == "" ||
Request->ContentFields->Values["Password"] == "")
{
Response->Content = ppBlankField->Content();
}
else if (AuthenticateUser(Request->ContentFields->Values["UserName"],
Request->ContentFields->Values["Password"]))
{
Response->Location = Request->ContentFields->Values["URL"];
}
else
{
Response->Content = ppLoginFailed->Content();
}
Handled = true;
}
//---------------------------------------------------------------------------
bool TWebModule1::AuthenticateUser(AnsiString UN, AnsiString PW)
{
// Construct SQL query
Query->SQL->Add("SELECT DISTINCT UserName, Password "
"FROM Users "
"WHERE UserName = " + UN);
// Execute the query
Query->Active = true;
if (Query->RecordCount == 0)
{
// Close the Query
Query->Active = false;
return false;
}
// Validate password
if (PW == Query->FieldByName("Password")->AsString)
{
// Close the Query
Query->Active = false;
return true;
}
else
{
// Close the Query
Query->Active = false;
return false;
}
}
//---------------------------------------------------------------------------
Code:
object Database: TDatabase
Connected = True
DatabaseName = 'DBUsers'
LoginPrompt = False
SessionName = 'Default'
Left = 128
Top = 8
end
object Query: TQuery
DatabaseName = 'DBUsers'
Left = 128
Top = 56
end
Thanks in advance!