Flash login with php

  • rezzkilla
  • Beginner
  • Beginner
  • rezzkilla
  • Posts: 55
  • Loc: Alabama

Post 3+ Months Ago

I'm want a login in my flash movie. My setup contains two movies:
frame.swf
login.swf

login.swf loads into an empty movieclip in the frame.swf and contains two login fields for username and password. Frame 1 of the login.swf has the input fields and a submit button which goes to frame 2 for processing and activates my loadVars from there my script goes to pass or fail. However, when I run this program it goes to frame 2 and then does nothing. I've ran just my php and receive no errors. I'm stuck because I've got this working with a mail php script but not a database script. Any help or advice will be greatly appreciated.

dataOut = new LoadVars();
dataOut.fusername = user.text;
dataOut.fpassword = pass.text;
myData = new LoadVars();
myData.onLoad = function() {
if (this.response == "passed") {
_root.empty.gotoAndStop(6);
} else if (this.response == "error") {
_root.empty.gotoAndStop(5);
alert.text = "Login Failed.";
}
};
dataOut.sendAndLoad("processLogin.php", myData, "POST");


//processLogin.php//
<?php
$user=$_POST['fusername'];
$pass=$_POST['fpassword'];
include("rezzkilla.php");
connecttodb($servername,$dbname,$dbusername,$dbpassword);
function connecttodb($servername,$dbname,$dbuser,$dbpassword)
{
global $link;
$link=mysql_connect ("$servername","$dbuser","$dbpassword");
if(!$link){die("Could not connect to MySQL");}
mysql_select_db("$dbname",$link) or die ("could not open db".mysql_error());
}


$sql="SELECT * FROM customers WHERE loginName = '$user' AND password = '$pass'";
$result = mysql_query($sql) or die("Couldn't execute query.");
$num_rows = mysql_num_rows($result);
if($num_rows==0){
print "&response=error";
exit();
}
else {
print "&response=passed";
}
?>
I've used this setup with an email form and it works great, and I can't see why I can't post those two variables in (fusername/fpassword) and check them against a mysql database instead of mailing them.
  • rezzkilla
  • Beginner
  • Beginner
  • rezzkilla
  • Posts: 55
  • Loc: Alabama

Post 3+ Months Ago

I got it working.
Two input fields::one instance name user and one instance name pass with a SUBMIT button that goes to the next frame for processing and runs the following loadvars object code. Frame 6 is members page; Frame 5 is login failed page with dynamic textfield with an instance name of alert. Easy as Pie! Hope this helps someone.
FLash:
dataOut = new LoadVars();
dataOut.fuser = user.text;
dataOut.fpass = pass.text;
dataOut.onLoad = function() {
if (this.response == "passed") {
_root.empty.gotoAndStop(6);
} else {
_root.empty.gotoAndStop(5);
alert.text = "Login Failed! Registered users only! Please check your information and try again. Contact us if you continue to have problems.";
}
};
dataOut.sendAndLoad("processLogin.php", dataOut, "POST");

AND PHP:
loginInformation.php
<?php
$dbservertype='mysql';
$servername='website.com';
// username and password to log onto db server
$dbusername='admin';
$dbpassword='pass';
// name of database
$dbname='website_com_YourDB';
?>
processLogin.php
<?php
//connect to db
include("loginInformation.php");
connecttodb($servername,$dbname,$dbusername,$dbpassword);
function connecttodb($servername,$dbname,$dbuser,$dbpassword)
{
global $link;
$link=mysql_connect ("$servername","$dbuser","$dbpassword");
if(!$link){die("Could not connect to MySQL");}
mysql_select_db("$dbname",$link) or die ("could not open db".mysql_error());
}

//END connect to db

$fusern = $_POST['fuser'];
$fpassn = $_POST['fpass'];
$sql="SELECT * FROM customerLogin WHERE username = '$fusern' AND password = '$fpassn'";
$result = mysql_query($sql) or die("Couldn't execute query.");
$num_rows = mysql_num_rows($result);
if($num_rows > 0){
print "&response=passed";
exit();
}
else {
exit();
}
?>

Post Information

  • Total Posts in this topic: 2 posts
  • Users browsing this forum: No registered users and 19 guests
  • You cannot post new topics in this forum
  • You cannot reply to topics in this forum
  • You cannot edit your posts in this forum
  • You cannot delete your posts in this forum
  • You cannot post attachments in this forum
 
 

© 1998-2014. Ozzu® is a registered trademark of Unmelted, LLC.