Recent

Author Topic: Help! Login program can't check the credentials!  (Read 8125 times)

workinghard

  • Jr. Member
  • **
  • Posts: 74
Help! Login program can't check the credentials!
« on: April 29, 2012, 10:53:11 am »
So i was making a login program (using only 1 parameter, which is the address) and for reasons that i don't know, it can't do anything except telling me that the address is not found
Code: [Select]
begin
     qcalc.Close;
     qcalc.sql.clear;
     qcalc.sql.add('SELECT * FROM Master WHERE master.address='+QuotedStr(Address.Text));

    if Qcalc.recordcount = 0 then
    begin
    showmessage('Address not found');
    end 

Where did i mess up? In the master table there are already lots of addressess, and each one of them doesn't work when tested
« Last Edit: April 29, 2012, 10:56:51 am by workinghard »

BigChimp

  • Hero Member
  • *****
  • Posts: 5740
  • Add to the wiki - it's free ;)
    • FPCUp, PaperTiger scanning and other open source projects
Re: Help! Login program can't check the credentials!
« Reply #1 on: April 29, 2012, 11:43:47 am »
Start reading some documentation as lots of us already asked you to do.

Try to look up the answer to some question:
How do you execute a query?
Why is it a bad idea to use QuotedStr unless you REALLY know what you're doing? (Hint: parameters, entering Jim's 12" Steak Knife as data, or perhaps "The Willows", 12 O'Malley Drive, Maplewood)

Good luck
Want quicker answers to your questions? Read http://wiki.lazarus.freepascal.org/Lazarus_Faq#What_is_the_correct_way_to_ask_questions_in_the_forum.3F

Open source including papertiger OCR/PDF scanning:
https://bitbucket.org/reiniero

Lazarus trunk+FPC trunk x86, Windows x64 unless otherwise specified

workinghard

  • Jr. Member
  • **
  • Posts: 74
Re: Help! Login program can't check the credentials!
« Reply #2 on: April 30, 2012, 01:09:35 am »
Following your advice, i changed the code to this:
Code: [Select]
     qcalc.Close;
     qcalc.sql.clear;
     qcalc.sql.add('SELECT * FROM Master WHERE master.address:=Address');
     qcalc.Params.ParamByName('Address').AsString := Address.text;


When I ran the program again, i got the error saying parameter Address not found...
this error has been present for quite a while now...
« Last Edit: April 30, 2012, 03:06:30 am by workinghard »

goldenfox

  • New Member
  • *
  • Posts: 47
Re: Help! Login program can't check the credentials!
« Reply #3 on: April 30, 2012, 05:33:33 am »
it should be something like

Quote
qcalc.sql.add('SELECT * FROM Master WHERE master.address=:Address');
qcalc.Params.ParamByName('Address').AsString := Address.text;

Notice the bold =:

workinghard

  • Jr. Member
  • **
  • Posts: 74
Re: Help! Login program can't check the credentials!
« Reply #4 on: April 30, 2012, 11:08:37 am »
it should be something like

Quote
qcalc.sql.add('SELECT * FROM Master WHERE master.address=:Address');
qcalc.Params.ParamByName('Address').AsString := Address.text;

Notice the bold =:

I've tried it man, it doesn't work
The code is now:
Code: [Select]
begin
     qcalc.Close;
     qcalc.sql.clear;
     qcalc.sql.add('SELECT * FROM master WHERE address=:Address');
     qcalc.Params.ParamByName('Address').AsString := Address.text;

    if QHitung1.recordcount = 0 then
    begin
    showmessage('Address not found!');
    end   
 

Arbee

  • Full Member
  • ***
  • Posts: 223
Re: Help! Login program can't check the credentials!
« Reply #5 on: April 30, 2012, 11:12:59 am »
Is this the complete code?
I do not see you executing the SQL statement anywhere (via an "open").
1.0/2.6.0  XP SP3 & OS X 10.6.8

joseme

  • Full Member
  • ***
  • Posts: 128
    • Logosoft sistemas
Re: Help! Login program can't check the credentials!
« Reply #6 on: April 30, 2012, 11:14:39 am »
You should open the query after passing the parameter, the code should be something like
Code: [Select]
begin
     qcalc.Close;
     qcalc.sql.clear;
     qcalc.sql.add('SELECT * FROM master WHERE address=:Address');
     qcalc.Params.ParamByName('Address').AsString := Address.text;
     qcalc.open;

    if qcalc.recordcount = 0 then
    begin
    showmessage('Address not found!');
    end   
 
un aporte a la comunidad:
http://pascalylazarus.blogspot.com/

workinghard

  • Jr. Member
  • **
  • Posts: 74
Re: Help! Login program can't check the credentials!
« Reply #7 on: April 30, 2012, 11:24:04 am »
Following Joseme's advice i've added the qcalc.open code. And now the code goes like this

Code: [Select]
begin
     qcalc.Close;
     qcalc.sql.clear;
     qcalc.sql.add('SELECT * FROM master WHERE address=:Address');
     qcalc.Params.ParamByName('Address').AsString := Address.text;
     qcalc.open;

    if qcalc.recordcount = 0 then
    begin
    showmessage('Address not found!');
    end   
    else

    begin
      Qcalc.Close;
      Qcalc.sql.clear;
      Qcalc.sql.text:='INSERT INTO trmt VALUES (address.text), CURRENT_TIMESTAMP, 20000, (
SELECT (M.land*RM.landrate)+(M.bldg*RM.bldgrate)
FROM MASTER AS M, Rmnt AS RM
WHERE M.Address := address AND M.Cluster = RM.Cluster)';
      QHitung1.execSQL;
      TransHitung.commit;

      Qcalc.sql.clear;
      Qcalc.sql.text:='
INSERT INTO trair
VALUES (edAddress), CURRENT_TIMESTAMP,(

SELECT M.PemAirTrkr
FROM MASTER AS M
WHERE M.Address:=EdAddress), edMTA, (BAw-BAk)';
      Qcalc.execSQL;
      Transcalc.commit;

      Qcalc.sql.clear;
      Qcalc.sql.text:='UPDATE master SET PemAirTrkr = edMTA WHERE Alamat = EdAddress';
      Qcalc.ExecSQL;
      Transcalc.Commit;
    end;
end;                     
 

It still raises the same old error
Do i mess up somewhere else?
« Last Edit: April 30, 2012, 11:29:27 am by workinghard »

joseme

  • Full Member
  • ***
  • Posts: 128
    • Logosoft sistemas
Re: Help! Login program can't check the credentials!
« Reply #8 on: April 30, 2012, 12:05:06 pm »
This is very strange, your code is correct. Can you run this simple code?
Code: [Select]
qCalc.close;
qCalc.Text := 'select * from master';
qCalc.open;
showMessage(qCalc.fieldbyname('Address').Asstring)
It should show you the first address in the table.

un aporte a la comunidad:
http://pascalylazarus.blogspot.com/

workinghard

  • Jr. Member
  • **
  • Posts: 74
Re: Help! Login program can't check the credentials!
« Reply #9 on: April 30, 2012, 12:57:47 pm »
I do this:
Code: [Select]
procedure TForm3.Button1Click(Sender: TObject);

begin
  qcalc.close;
  qcalc.clear;
  qcalc.add := 'SELECT * FROM Master';
  qcalc.open;

  showmessage(qcalc.fieldbyname('address').asstring) ;
end;


And I get this error:
Quote
unit3.pas(58,12) Error: identifier idents no member "clear"
unit3.pas(59,12) Error: identifier idents no member "add"
unit3.pas(62,22) Error: Identifier not found "qcalc"
unit3.pas(67) Fatal: There were 3 errors compiling module, stopping

And using this syntax:
Code: [Select]
qCalc.close;
qCalc.Text := 'select * from master';
qCalc.open;
showMessage(qCalc.fieldbyname('Address').Asstring)

I have this error:
Quote
unit3.pas(58,12) Error: identifier idents no member "text"
unit3.pas(61,22) Error: Identifier not found "qcalc"
unit3.pas(66) Fatal: There were 2 errors compiling module, stopping

Oh, and by using this:
Code: [Select]
begin
  qcalc.sql.close;
  qcalc.sql.text := 'SELECT * FROM Master';
  qcalc.sql.open;

  showmessage(qhitung.fieldbyname('address').asstring) ;
end;

This showed up:
Quote
unit3.pas(57,16) Error: identifier idents no member "close"
unit3.pas(59,16) Error: identifier idents no member "open"
unit3.pas(61,22) Error: Identifier not found "qcalc"
unit3.pas(66) Fatal: There were 3 errors compiling module, stopping

Is there anything wrong with my SQL library then?

I use Lazarus 0.9.30.4 with FPC 2.6.0 in Win7 Home Premium x64
Also I installed it in drive D, since the drive C has the older version and I still need it...
« Last Edit: April 30, 2012, 01:03:06 pm by workinghard »

workinghard

  • Jr. Member
  • **
  • Posts: 74
Re: Help! Login program can't check the credentials!
« Reply #10 on: May 01, 2012, 05:55:38 pm »
please, anyone?

dr4cul453xy

  • New member
  • *
  • Posts: 7
Re: Help! Login program can't check the credentials!
« Reply #11 on: May 16, 2012, 11:00:18 am »
I do this:
Code: [Select]
procedure TForm3.Button1Click(Sender: TObject);

begin
  qcalc.close;
  qcalc.clear;  // <<<<< THIS ONE
  qcalc.add := 'SELECT * FROM Master'; // <<<<< and THIS ONE
  qcalc.open;

  showmessage(qcalc.fieldbyname('address').asstring) ;
end;

I think you  messed up something (the marked part). the debugger has already told you what to do :)
it should be as follow :
Code: [Select]
  qcalc.close;
  qcalc.SQL.clear;  // <<<<< CHANGE TO THIS ONE
  qcalc.SQL.add := 'SELECT * FROM Master'; // <<<<< CHANGE TO THIS ONE
  qcalc.open;

please let me know if it still raising error.. ;D
drx

 

TinyPortal © 2005-2018