Recent

Author Topic: [HELP] Connecting to a SQL Database tables?- Console Application  (Read 43327 times)

nobodyknowsme

  • Full Member
  • ***
  • Posts: 114
Re: [HELP] Connecting to a SQL Database tables?- Console Application
« Reply #60 on: December 21, 2014, 02:34:31 pm »
Yeah writeln();however I want it linking from the console. I can't see the post from that??

nobodyknowsme

  • Full Member
  • ***
  • Posts: 114
Re: [HELP] Connecting to a SQL Database tables?- Console Application
« Reply #61 on: December 21, 2014, 02:36:25 pm »
Premium := Result and (Query.FieldByNa

How can the message read from the SQL database?

rvk

  • Hero Member
  • *****
  • Posts: 7045
Re: [HELP] Connecting to a SQL Database tables?- Console Application
« Reply #62 on: December 21, 2014, 02:44:37 pm »
Premium := Result and (Query.FieldByNa
How can the message read from the SQL database?
I said you needed to add a line UNDER that "premium :=" line.

I said it in this post:
I can't completely write all the code for you. If you've already wrote the game you should be able to add some code to simply read out a message-field from the users-table in the code you've already got. If you get in trouble you can post your code here with a clear error message.

You would need some line like this:
Code: [Select]
Message := Query.FieldByName('message').AsString;
right under the premium := line.

After that you can display the message-string to the user just before you jump to your game.
You just need to define the message variable yourself (surely you can do that) and print it to the console with writeln (seeing as you wrote a console-game you should be able to do that too).

nobodyknowsme

  • Full Member
  • ***
  • Posts: 114
Re: [HELP] Connecting to a SQL Database tables?- Console Application
« Reply #63 on: December 21, 2014, 02:48:56 pm »
im confused sorry! That message is wrong from their account? On there information. So if the user test had the message 'test' that would display?? Also making it read to the console? Would I just to writeln(message); and have the message as a variable?

rvk

  • Hero Member
  • *****
  • Posts: 7045
Re: [HELP] Connecting to a SQL Database tables?- Console Application
« Reply #64 on: December 21, 2014, 03:35:32 pm »
im confused sorry! That message is wrong from their account? On there information. So if the user test had the message 'test' that would display??
Yes... From your screenshot I could see you have a user "" (empty) with a message but a user "test" without a message. The message needs to be filled in in the same record as that user. If you need to give all the users the same message you could run an SQL-script filling in the message field for all the users. But as it is now only the user "" (empty) had a message. (You did know you added a second user, did you?) So every message to every user can be different. (For example... "your account has been cancelled" could be a message to one user for which you have set premium to 0 because his payment didn't come through)

Also making it read to the console? Would I just to writeln(message); and have the message as a variable?
Yes. If you set the field message for the record of user test (you can use the edit button in the phpmyadmin-site) that record is read in the variable "message" (for which you need to add that line under the premium line as stated in previous posts) and after that you can just writeln(message) to display the message. (You'll need to make "message" a global variable just as the variable "user" and "premium".)

nobodyknowsme

  • Full Member
  • ***
  • Posts: 114
Re: [HELP] Connecting to a SQL Database tables?- Console Application
« Reply #65 on: December 22, 2014, 01:47:59 pm »
I made it a global variable and when they logged in it would display on the online message board. Why wont it display?

nobodyknowsme

  • Full Member
  • ***
  • Posts: 114
Re: [HELP] Connecting to a SQL Database tables?- Console Application
« Reply #66 on: December 22, 2014, 01:51:00 pm »
EDIT: Im not using the premium yet. Im using your idea of them just having a username and password.

rvk

  • Hero Member
  • *****
  • Posts: 7045
Re: [HELP] Connecting to a SQL Database tables?- Console Application
« Reply #67 on: December 22, 2014, 01:53:20 pm »
EDIT: Im not using the premium yet. Im using your idea of them just having a username and password.
And where did you put the writeln-line?
If it's only displaying for premium users it won't display because you haven't made user test premium yet.

It's working for me if I put the writeln for non-premium too.

Otherwise you need to show your code.

rvk

  • Hero Member
  • *****
  • Posts: 7045
Re: [HELP] Connecting to a SQL Database tables?- Console Application
« Reply #68 on: December 22, 2014, 01:55:30 pm »
I made it a global variable and when they logged in it would display on the online message board. Why wont it display?
And why did you put the "message :="-line in the wrong place ???
Where did I ask you to put it?

(You are trying to read message out before you opened the table. It needs to be after open.)

And this is also not the last code I gave you (with the premium stuff in it).
« Last Edit: December 22, 2014, 01:58:45 pm by rvk »

nobodyknowsme

  • Full Member
  • ***
  • Posts: 114
Re: [HELP] Connecting to a SQL Database tables?- Console Application
« Reply #69 on: December 22, 2014, 02:12:00 pm »
Becuase I said I was going to have the usernames and passwords. Sorry for the confusion. I am fairly new at this. You've been a really big help. Thank you :)

nobodyknowsme

  • Full Member
  • ***
  • Posts: 114
Re: [HELP] Connecting to a SQL Database tables?- Console Application
« Reply #70 on: December 22, 2014, 02:13:53 pm »
Ah thank you very much it works! How would I get it to display before they're entering there usernames and passwords. Like an update log that I can update. So display the message before they log in.

rvk

  • Hero Member
  • *****
  • Posts: 7045
Re: [HELP] Connecting to a SQL Database tables?- Console Application
« Reply #71 on: December 22, 2014, 02:23:37 pm »
How would I get it to display before they're entering there usernames and passwords. Like an update log that I can update. So display the message before they log in.
In that case you would need a generic message.
But you would need to retrieve it separately because the message-lines we've got now are tied to the user.

You could make a special user without password (Like User "all" and leave password empty).

You could do something like this:
Code: [Select]
  function GetGenericMessage: String;
  var
    Query: TSQLQuery;
    Password: string;
  begin
    Result := '';
    Query := TSQLQuery.Create(nil);
    Query.Database := AConnection;
    Query.Transaction := TSQLTransaction.Create(Query);
    Query.Transaction.Database := AConnection;
    Query.SQL.Text := 'select * from users where username=''all''';
    Query.Open;
    if (Query.RecordCount > 0) then Result := Query.FieldByName('message').AsString;
    Query.Close;
    Query.Free;
  end;

  function GetValidUsername: boolean;
  var
    Query: TSQLQuery;
    Password: string;
    MessageAll: String;
  begin
    Result := False;
    MessageAll := GetGenericMessage;
    if MessageAll <> '' then writeln('Message to all: ' + GetGenericMessage);
    repeat
      Write('Username: ');
      ReadLn(User);
    until User <> '';
    repeat
      Write('Password: ');
      ReadLn(Password);
    until Password <> '';
    Query := TSQLQuery.Create(nil);
    Query.Database := AConnection;
    Query.Transaction := TSQLTransaction.Create(Query);
    Query.Transaction.Database := AConnection;
    Query.SQL.Text := 'select * from users where username=:username and password=:password';
    Query.ParamByName('username').AsString := User;
    Query.ParamByName('password').AsString := Password;
    Query.Open;
    Result := Query.RecordCount > 0;
    Message := Query.FieldByName('message').AsString; // <-- this is the user-specific message
    Query.Close;
    Query.Free;
  end;

Because password is empty (and you don't accept users with an empty password) nobody could login with username "all" but you can use that one to display a generic message.

nobodyknowsme

  • Full Member
  • ***
  • Posts: 114
Re: [HELP] Connecting to a SQL Database tables?- Console Application
« Reply #72 on: December 22, 2014, 02:44:28 pm »
OKay it works however there is one problem. The username can be right and the password can be anything and it will enter.

rvk

  • Hero Member
  • *****
  • Posts: 7045
Re: [HELP] Connecting to a SQL Database tables?- Console Application
« Reply #73 on: December 22, 2014, 02:47:46 pm »
OKay it works however there is one problem. The username can be right and the password can be anything and it will enter.
Then you need to show the complete code.
Please copy and paste it in a message between code-tags.

rvk

  • Hero Member
  • *****
  • Posts: 7045
Re: [HELP] Connecting to a SQL Database tables?- Console Application
« Reply #74 on: December 22, 2014, 02:58:11 pm »
Uuuuuh.... Why is you password of type int(50) in your database (and not varchar(50)) ???  :o

That throws of the whole check on "password=:password" part in the SQL  :)
Now only real-numbers are checked. And your "sdhjfhkahfhjfkahkjdsf"-password evaluates to 0 (because it's seen as a variable) so it's always true.

Change your password to a varchar(50) and the SQL should do the check just fine.

 

TinyPortal © 2005-2018