|
I made a login interface, clicked the add user button, and added the user, but I entered the login box into the login box, and an error occurred, saying that the database does not have this user field. After I closed the program and re-run it, I could log in again. Why can't I log in directly after adding, my code is as follows.
Add button code: procedure checkinput (theedit: tedit; strdesc: string);
begin
theedit.Text: = trim (theedit.Text);
theedit.Text: = stringreplace (theedit.Text, `` '', '', [rfreplaceall]);
theedit.Text: = stringreplace (theedit.Text, '', '', [rfreplaceall]);
if theedit.Text = '' then
begin
showmessage (strdesc);
theedit.SetFocus;
abort;
end;
end;
begin
checkinput (edit1, 'Please enter an operator name!');
checkinput (edit2, 'Please enter your password!');
with query1 do
begin
active: = false;
sql.Clear;
sql.Add ('insert into users (username, passwd)');
sql.Add ('values ((: a), (: b))');
params [0] .AsString: = edit1.Text;
params [1] .AsString: = edit2.Text;
execSQL;
end;
showmessage ('Added successfully!');
edit1.Clear;
edit2.Clear;
Login button code:
procedure checkinput (theedit: tedit; strdesc: string);
begin
theedit.Text: = trim (theedit.Text);
theedit.Text: = stringreplace (theedit.Text, `` '', '', [rfreplaceall]);
theedit.Text: = stringreplace (theedit.Text, '', '', [rfreplaceall]);
if theedit.Text = '' then
begin
showmessage (strdesc);
theedit.SetFocus;
abort;
end;
end;
begin
checkinput (edtusername, 'Please enter an operator name!');
checkinput (edtPasswd, 'Please enter a password!');
query1.Active: = false;
query1.ParamByName ('UserName'). AsString: = edtusername.Text;
query1.ParamByName ('passwd'). AsString: = edtpasswd.Text;
query1.Active: = true;
if query1.Eof then
begin
showmessage ('The operator name or password is incorrect!');
edtusername.SetFocus;
inc (times);
end
else
modalresult: = mrOK;
if times> = 3 then
begin
showmessage ('Illegal user is not authorized to log in!');
modalresult: = mrcancel;
end; |
|