FORUMS: list search recent posts

Login script - revisited

COW Forums : Adobe Flash

<< PREVIOUS   •   FAQ   •   VIEW ALL   •   PRINT   •   NEXT >>
Char Cole
Login script - revisited
on Jul 20, 2008 at 6:40:54 am

I have a login script that checks if the username and password are in the database and if so lets you in. It currently works.

PHP Code:

session_start();
$user = $_POST['user'];
$password = $_POST['pass'];

//mysqldetails
require_once("config.php");

$SQL = "SELECT * FROM account WHERE login ='".$user."' AND password = '".$password."'";
$rs = mysql_query($SQL,$conn);
$numRows = mysql_num_rows($rs);

if($numRows > 0){
$_SESSION['loggedIn'] = true;
echo 'login=success';
}else{
echo 'login=failure';
}

?>


ActionScript 2.0

var lvSend:LoadVars = new LoadVars();
var lvReceive:LoadVars = new LoadVars();

tError.autoSize = "right";

mcLogin.onRelease = function() {

//Global Variable
_global.username = tUser.text;

lvSend.user = tUser.text;
lvSend.pass = tPassword.text;
lvSend.sendAndLoad("logincheck.php", lvReceive, "POST");
};

lvReceive.onLoad = function(success:Boolean) {
if (success) {
if (this.login == "success") {
gotoAndPlay("Main Menu", "Main Menu_start");
} else {
tError.text = "LOGIN ERROR: You typed it in wrong!";
}
} else {
trace("no reponse from server");
}
};


However now I need the ability to check if two variables are in the database in order to login and decide which scene you will go to from there. But nothing I have tried has worked. Here is the code that I am working with now.

PHP Code

session_start();
$user = $_POST['user'];
$password = $_POST['pass'];

//mysqldetails
require_once("config.php");

$SQL = "SELECT * FROM account WHERE login ='".$user."' AND password = '".$password."'";
$rs = mysql_query($SQL,$conn);
$numRows = mysql_num_rows($rs);

$SQL2 = "SELECT * FROM account WHERE login ='".$user."'";
$rs2 = mysql_query($SQL2,$conn);
$numRows2 = mysql_num_rows($rs2);

if($numRows > 0 && $numRows2 > 0){
$_SESSION['loggedIn'] = true;
echo 'login=successin';
}else if($numRows > 0 && $numRows2 > 0){
$_SESSION['loggedIn'] = true;
echo 'login=successnew';
}else {
echo 'login=failure';
}

?>


ActionScript 2.0

stop();

var lvSend:LoadVars = new LoadVars();
var lvReceive:LoadVars = new LoadVars();

tError.autoSize = "right";

mcLogin.onRelease = function() {

//Global Variable
_global.username = tUser.text;

lvSend.user = tUser.text;
lvSend.pass = tPassword.text;
lvSend.sendAndLoad("logincheck.php", lvReceive, "POST");
};

lvReceive.onLoad = function(success:Boolean) {
if (success) {
if (this.login == "successin") {
gotoAndPlay("Main Menu", "Main Menu_start");
} else if (this.login == "successnew") {
gotoAndPlay("Main Menu", "Main Menu_start");
} else {
tError.text = "LOGIN ERROR: You typed it in wrong!";
}
} else {
trace("no reponse from server");
}
};


Any help would be appreciated!

Char

"I think... I think it's in my basement... Let me go upstairs and check!" - M.C.Escher


Return to posts index

Pieter Helsen
Re: Login script - revisited
on Jul 20, 2008 at 9:44:03 am

Aren't these exactly the same?

if($numRows > 0 && $numRows2 > 0){
$_SESSION['loggedIn'] = true;
echo 'login=successin';
}else if($numRows > 0 && $numRows2 > 0){
$_SESSION['loggedIn'] = true;
echo 'login=successnew';
}


Actionscript:

if (this.login == "successin") {
gotoAndPlay("Main Menu", "Main Menu_start");
} else if (this.login == "successnew") {
gotoAndPlay("Main Menu", "Main Menu_start");
}


And what exactly is, or isn't it doing? :)

From now on, I would like to ask everyone to put [AS2] or [AS3] (corresponding to the version of actionscript you are using on your project) in front of their post titles when the question is actionscript related! Please help us help you faster. Thank you.

Kind regards,
Pieter


Return to posts index

Char Cole
Re: Login script - revisited [AS] 2.0
on Jul 20, 2008 at 9:52:02 am

Sorry if I didnt put the ActionScript 2.0 in the right spot. I thought putting it above the actual actionscript area would work but I promise Ill put it in the title from now on :)

Yes they are. I accidently copied the wrong code the second time. it shoud say:

if($numRows > 0 && $numRows2 > 0){
$_SESSION['loggedIn'] = true;
echo 'login=successin';
}else if($numRows > 0 && $numRows2 == 0){
$_SESSION['loggedIn'] = true;
echo 'login=successnew';
}

Changing the second part from > to ==



"I think... I think it's in my basement... Let me go upstairs and check!" - M.C.Escher


Return to posts index


Pieter Helsen
Re: Login script - revisited [AS] 2.0
on Jul 20, 2008 at 10:21:05 am

Don't worry, that message gets attached as a signature to my posts now for a while, I know you usually use AS2 ;)

It's just so other people will learn to do it as well. It also doesn't really matter where you put it, in the title or in the message, in the title just seemed more convenient to me.

else if($numRows > 0 && $numRows2 == 0){

Shouldn't this be the other way around?
Because the first query checks for username and password and the second checks for just the username so if $numrows is greater than 0, $numrows2 has to be aswell, right?

Other than that, the script looks okay. Try debugging a little more using trace() commands to see where the script takes you exactly and then let me know what it's doing and what it is supposed to be doing :)



From now on, I would like to ask everyone to put [AS2] or [AS3] (corresponding to the version of actionscript you are using on your project) in front of their post titles when the question is actionscript related! Please help us help you faster. Thank you.

Kind regards,
Pieter


Return to posts index

Char Cole
Re: Login script - revisited [AS] 2.0
on Jul 20, 2008 at 10:27:07 am

LOL will do!

ACtually the firs tpart checks to see if there is a username and password in one table and the same username in another table = go right into the main area.

The second one checks to see if the username and pass are in the first table and is there is not the same username in another table = go do one more step before accessing the rest of the areas.

Sorry if this doesnt make any sense. Been working on this project for most of the day/night and the whole writing back to flash with Variables had my head spinning until I got your email. You know your explination was probably the easiest to understand that I have found all day/night LOL.

Thanks again will let you know what the trace says!

Char

"I think... I think it's in my basement... Let me go upstairs and check!" - M.C.Escher


Return to posts index

Char Cole
Re: Login script - revisited [AS] 2.0
on Jul 20, 2008 at 8:35:28 pm

Ok I ran a trace and this.login came back undefined which of course makes it go directly to the error text.

ActionScript 2.0

lvReceive.onLoad = function(success:Boolean) {
if (success) {
trace(this.login);
if (this.login == "successin") {
gotoAndPlay("Main Menu", "Main Menu_start");
} else if (this.login == "successnew") {
gotoAndPlay("Character", "character_start");
} else {
tError.text = "LOGIN ERROR: You typed it in wrong!";
}
} else {
trace("no reponse from server");
}
};



I even changed the PHP script like you suggested (after trying it my way too ;) )

PHP Code

session_start();
$user = $_POST['user'];
$password = $_POST['pass'];

//mysqldetails
require_once("config.php");

$SQL = "SELECT * FROM account WHERE login ='".$user."' AND password = '".$password."'";
$rs = mysql_query($SQL,$conn);
$numRows = mysql_num_rows($rs);

$SQL2 = "SELECT * FROM account WHERE login ='".$user."'";
$rs2 = mysql_query($SQL2,$conn);
$numRows2 = mysql_num_rows($rs2);

if($numRows > 0 && $numRows2 > 0){
$_SESSION['loggedIn'] = true;
echo 'login=successin';
}else if($numRows2 == 0 && $numRows > 0){
$_SESSION['loggedIn'] = true;
echo 'login=successnew';
}else {
echo 'login=failure';
}

?>


Going to go test one more thing but any guidance would leave some hair on my head at this point ;)

Char

"I think... I think it's in my basement... Let me go upstairs and check!" - M.C.Escher


Return to posts index


Pieter Helsen
Re: Login script - revisited [AS] 2.0
on Jul 20, 2008 at 8:39:52 pm

Debug the PHP by using GET instead of POST and testing the PHP individually. An undefined loadvars usually means somethings wrong with the PHP syntax.

From now on, I would like to ask everyone to put [AS2] or [AS3] (corresponding to the version of actionscript you are using on your project) in front of their post titles when the question is actionscript related! Please help us help you faster. Thank you.

Kind regards,
Pieter


Return to posts index

Char Cole
Re: Login script - revisited [AS] 2.0
on Jul 20, 2008 at 8:48:09 pm

Ok LOL forgive my probably rather NEWBIE question/Statment here but when I do that and I test through the IDE I get:

no reponse from server
Error opening URL 'file:///C|/Documents%20and%20Settings/Modern%20Merlin/My%20Documents/WizeGuyzGamez/logincheck.php?pass=test&user=test'


When I do it on the server I still just get the login error and nothing changes in the address bar.

Char

"I think... I think it's in my basement... Let me go upstairs and check!" - M.C.Escher


Return to posts index

Pieter Helsen
Re: Login script - revisited [AS] 2.0
on Jul 20, 2008 at 8:52:54 pm

Heh, I meant, test the PHP file seperately. :) Run the PHP file on your localhost. Don't use Flash to run it, see if PHP throws any errors at you. (You can't test this in flash because the php file gets called in the background)

From now on, I would like to ask everyone to put [AS2] or [AS3] (corresponding to the version of actionscript you are using on your project) in front of their post titles when the question is actionscript related! Please help us help you faster. Thank you.

Kind regards,
Pieter


Return to posts index


Char Cole
Re: Login script - revisited [AS] 2.0
on Jul 20, 2008 at 9:24:38 pm

Ok at this point here is what is going on:

It kicks back an actual variable now but it kicks back the second one no matter what is entered.

//mysqldetails
require_once("config.php");

$SQL = "SELECT * FROM account WHERE login ='".$user."' AND password = '".$password."'";
$rs = mysql_query($SQL,$conn);
$numRows = mysql_num_rows($rs);

$SQL2 = "SELECT * FROM mobster WHERE account_id ='".$user."'";
$rs2 = mysql_query($SQL2,$conn);
$numRows2 = mysql_num_rows($rs2);

if($numRows > 0 && $numRows2 > 0){
if($numRows2 == 0 && $numRows > 0){
$_SESSION['loggedIn'] = true;
echo '&login=successnew&';
}else {
$_SESSION['loggedIn'] = true;
echo '&login=successin&';
}
}


"I think... I think it's in my basement... Let me go upstairs and check!" - M.C.Escher


Return to posts index

Char Cole
Re: Login script - revisited [AS] 2.0
on Jul 20, 2008 at 8:54:24 pm

LMAO ok wait! LOL Hold the train! LOL

I realized what I did wrong. I missed the & signs around the login=successin and login=successnew.

Going to try it now.

Char

"I think... I think it's in my basement... Let me go upstairs and check!" - M.C.Escher


Return to posts index

Zach Albrecht
Re: Login script - revisited [AS] 2.0
on Aug 24, 2010 at 10:36:25 pm

I know this is a long dead post but after seriously searching for days on end and only finding tid bits of information, does anyone have the AS3 version of this coding or something very similar?

I'm new to actionscript and I'm trying to learn how to login by utilizing either the phpbb3 script(ucp.php?mode=login)or something similar to what is posted above. I would truly appreciate some help and I'd even pay a little for someone to teach me this specifically.


Return to posts index

<< PREVIOUS   •   VIEW ALL   •   PRINT   •   NEXT >>
© 2018 CreativeCOW.net All Rights Reserved
[TOP]