I am probably doing this horribly wrong, but I am really new to SQL and would appreciate ANY advice given.
Basically my aim is to make a login box.
I have made it, it works. BUT It only allows you to login to the LAST created Account and Password Row, it seems all others are ignored.
Here is the GUI I am using to login.
PHP Code:
findplayer("Graal780374").addweapon(name);
function onActionServerSide(){
if(params[0] == "Login"){
temp.req = requestsql("SELECT * FROM Accounts", true);
for (temp.row: temp.req.rows)
if(params[1] == temp.row.Account && params[2] == temp.row.Password){
player.chat = "Sucessful Username Entered!";
}else{
player.chat = "Failed Login!";
}
}
}
//#CLIENTSIDE
function onCreated() {
new GuiWindowCtrl("Login_Window") {
profile = GuiBlueWindowProfile;
clientrelative = true;
clientextent = "154,124";
canclose = false;
canmaximize = false;
canminimize = false;
canmove = false;
canresize = true;
closequery = false;
destroyonhide = false;
x = (screenwidth/2) - (width/2);
y = (screenheight/2) - (height/2);
alpha = 1;
new GuiTextCtrl("Login_Text") {
profile = GuiBlueTextProfile;
height = 20;
text = "Login";
width = 32;
x = 58;
y = 5;
}
new GuiTextCtrl("Account_Text") {
profile = GuiBlueTextProfile;
height = 20;
text = "Account";
width = 48;
x = 6;
y = 35;
}
new GuiTextCtrl("Password_Text") {
profile = GuiBlueTextProfile;
height = 20;
text = "Password";
width = 57;
x = 6;
y = 60;
}
new GuiTextEditCtrl("Account_TextEdit") {
profile = GuiBlueTextEditProfile;
height = 20;
width = 80;
x = 69;
y = 36;
text = "";
}
new GuiTextEditCtrl("Password_TextEdit") {
profile = GuiBlueTextEditProfile;
height = 20;
width = 80;
x = 69;
y = 61;
text = "";
}
new GuiButtonCtrl("Login_Button") {
profile = GuiBlueButtonProfile;
text = "Login";
width = 55;
height = 25;
x = 100;
y = 100;
}
new GuiButtonCtrl("Register_Button") {
profile = GuiBlueButtonProfile;
text = "Register";
width = 55;
height = 25;
y = 100;
x = -1;
}
}
}
function Login_Button.onAction() {
triggerserver("weapon", this.name, "Login", Account_TextEdit.text, Password_TextEdit.text);
}
And here is what i am doing to create the tables, which DOES work.
PHP Code:
requestsql("CREATE TABLE Accounts (Account varchar not null default '' primary key, Password int not null default 1)", false);
requestsql("INSERT INTO Accounts VALUES ('Account', 'Password')", false);
requestsql("INSERT INTO Accounts VALUES ('Account2', 'Password2')", false);
temp.req = requestsql("SELECT * FROM Accounts", true);
if (!temp.req.completed)
waitfor(temp.req,"onReceiveData",60);
echo("Accounts in database: " @ temp.req.rows.size());
for (temp.row: temp.req.rows)
echo("SQL: "@temp.row.Account@" "@temp.row.Password);
As I stated i am probably doing it extremely wrong.