
January 4th, 2013, 03:49 PM
|
|
|
I don't do fish but you will get answer much quicker by placing this in the correct forum.
Quote: | Originally Posted by vintage89 Hi guys,
I'm currently having my final year project now and i really need help as i'm new to actionscript 3.0 > php > mysql connection. I feel so ridiculous to not know how to solve this "simple login code". So, here goes...
Currently, after the button is being clicked, a successful message will appear --> print "systemResult=Welcome $username!";.
As you can see from the title of my thread, i want it to go to a new scene instead (in flash). I tried so many ways to do it but sadly, it didn't work. I really need help on this!!! Thanks guys!
[Actionscript]
package actions {
import flash.display.MovieClip;
import flash.events.*;
import flash.net.*;
import flash.text.*;
public class main extends MovieClip {
public function main ():void {
submit_button.buttonMode = true;
submit_button.addEventListener(MouseEvent.MOUSE_DOWN, checkLogin);
username.text = "";
password.text = "*";
}
public function checkLogin (e:MouseEvent):void {
if (username.text == "" || password.text == "") {
if (username.text == "") {
username.text = "Enter your username";
}
if (password.text == "") {
password.text = "Enter your password";
}
} else {
processLogin();
}
}
public function processLogin ():void {
var phpVars:URLVariables = new URLVariables();
var phpFileRequest:URLRequest = new URLRequest("login.php");
phpFileRequest.method = URLRequestMethod.POST;
phpFileRequest.data = phpVars;
var phpLoader:URLLoader = new URLLoader();
phpLoader.dataFormat = URLLoaderDataFormat.VARIABLES;
phpLoader.addEventListener(Event.COMPLETE, showResult);
phpVars.systemCall = "checkLogin";
phpVars.username = username.text;
phpVars.password = password.text;
phpLoader.load(phpFileRequest);
}
public function showResult (event:Event):void {
result_text.autoSize = TextFieldAutoSize.LEFT;
result_text.text = "" + event.target.data.systemResult;
}
}
}
[php] - login.php
<?php
include_once "dbconnect.php";
$username = $_POST['username'];
$password = $_POST['password'];
if ($_POST['systemCall'] == "checkLogin") {
$sql = "SELECT * FROM users WHERE username='$username' AND password='$password'";
$query = mysql_query($sql);
$login_counter = mysql_num_rows($query);
if ($login_counter > 0) {
print "systemResult=Welcome $username!";
} else {
print "systemResult=Invalid User!";
}
}
?> |
|