I am trying to create a user log-in system in Flash but I need to communicate to MySQL through PHP in order to do so. I looked around at a few tutorials, but I have been getting errors.
Here is the interface I have made in flash, which I am trying to communicate with controlpanel.php
https://i.stack.imgur.com/eB3C7.png
Here is the code
AS file
package actions
{
import flash.display.MovieClip;
import flash.events.MouseEvent;
import flash.net.URLRequest;
import flash.net.URLVariables;
import flash.net.URLLoader;
import flash.events.Event;
import flash.net.URLLoaderDataFormat;
import flash.net.URLRequestMethod;
import flash.text.TextFieldAutoSize;
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("http://mathlympics.cu.cc/php/controlpanel.php");
phpFileRequest.method = URLRequestMethod.POST;
phpFileRequest.data = phpVars;
var phpLoader:URLLoader=new URLLoader();
phpLoader.dataFormat = URLLoaderDataFormat.VARIABLES;
phpVars.systemCall = "checkLogin";
phpVars.username = username.text;
phpVars.password = password.text;
phpLoader.load(phpFileRequest);
phpLoader.addEventListener(Event.COMPLETE, showResult);
}
public function showResult(event:Event):void
{
result_text.autoSize = TextFieldAutoSize.LEFT;
result_text.text = ""+ event.target.data.systemResult;
}
}
}
PHP file – connect.php
<?php
$db_username = "censored";
$db_name = "censored";
$db_password = "censored";
$db_host = "mysql2.000webhost.com";
mysql_connect($db_host,$db_username, $db_password, $db_name);
mysql_select_db($db_name) or die (mysql_error());
?>
PHP file – controlpanel.php
<?php
error_reporting(E_ALL);
include_once("connect.php");
$username = "admin";
$password = "password";
$sql = "SELECT * FROM user WHERE username='$username' AND password='$password'";
$query = mysql_query($sql);
$login_counter = mysql_num_rows($query);
if ($login_counter > 0)
{
$data = mysql_fetch_array($query);
$userbio = $data["user_bio"];
echo "systemResult=" . $userbio;
}
else
{
echo "systemResult=Invalid";
}
?>
I do not get any error but when I press the submit button, is says undefined in the result text box, even when I type the right username and password.
<!-- Hosting24 Analytics Code -->
<script type="text/javascript" src="http://stats.hosting24.com/count.php"></script>
<!-- End Of Analytics Code -->
To those of you interested: Here is my website enter link description here
So the problem ended up being you had
SELECT * FROM user...when it should have beenSELECT * FROM users...=)