-
HELP!!! breeze over this PHP/Flash code?
Y'all ~
My ******** are up against the wall. Why can't I get this dang login to recognize the username/password? The Flash works fan-frickin-tastic, it just doesn't seem to be sending the data and allowing the user (username=admin; password=pass) to gain access:
Code:
stop();
login_lv = new LoadVars();
login_lv.onLoad=function(){
if(this.userInfo == "true"){
play();
welcome_txt.text="Welcome to the client area";
}else{
error_txt.text="Invalid data";
login_txt.text="";
password_txt.text="";
}
}
onLogin=function(){
if(login_txt.text.length<1){
error_txt.text="Please provide a login name";
}else if(password_txt.text.length<3){
error_txt.text="Invalid password";
password_txt.text="";
}else{
login_lv.fuser=login_txt.text;
login_lv.fpass=password_txt.text;
login_lv.sendAndLoad("processLogin.php", login_lv, "POST");
}
}
The main PHP file (processLogin.php):
PHP Code:
<?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();
}
?>
The PHP include file (loginInformation.php):
PHP Code:
<?php
$dbservertype='mysql';
$servername='gucciboy.com';
// username and password to log onto db server
$dbusername='admin';
$dbpassword='pass';
// name of database
$dbname='gucciboy_com_-_main';
?>
Flash file
PHP 1
PHP 2
A mighty big thanky ~
Rob
"hokey religions and ancient weapons are no match for a good blaster by your side, kid"
-
Registered User
hi,
Here are two steps to help you debug:
On the flash side:
PHP Code:
<?php
print "&response=passed&";
?>
If you test this php file with flash, and it works (you can login), you're flash is ok.
On the php side:
PHP Code:
<?php
//connect to db
include("loginInformation.php");
connecttodb($servername,$dbname,$dbusername,$dbpas sword);
function connecttodb($servername,$dbname,$dbuser,$dbpasswor d)
{
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
$_POST['fuser'] = 'admin';
$_POST['fpass'] = 'pass';
$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();
}
?>
Test this page alone (in the browser).
If you see response=passed& (note I added an extra & at the end), you're php works fine.
If it won't work with PHP and Flash, it could be the way variables are being sent.
Make sure you test in the browser, as the test player may send the variables via GET and not POST.
-
FK'n_dog
on the Flash side I would place the loadvars Object within the function to maintain scope.
stop();
onLogin = function(){
login_lv = new LoadVars();
login_lv.onLoad=function(){
if(this.userInfo == "true"){
play();
welcome_txt.text="Welcome to the client area";
}else{
error_txt.text="Invalid data";
login_txt.text="";
password_txt.text="";
}
};
if(login_txt.text.length<1){
error_txt.text="Please provide a login name";
}else if(password_txt.text.length<3){
error_txt.text="Invalid password";
password_txt.text="";
}else{
login_lv.fuser=login_txt.text;
login_lv.fpass=password_txt.text;
login_lv.sendAndLoad("processLogin.php", login_lv, "POST");
}
};
onLogin();
-
thanks
nunomira, thanks for the suggestion. the php works fine; i used a simple html form to test it after making a couple of minor mods to the php (mostly server name info) and it worked fine. the flash, though, for some reason still isn't working. i couldn't quite understand what your method of debugging for flash was, but then my brain's feeling kind of foggy right about now. i tried using 'get' vs. 'post'; no difference. i think it's due to either one of two things: the naming convention used for the text entry boxes:
Code:
login_lv.fuser=login_txt.text;
login_lv.fpass=password_txt.text;
or the method in which the data is passed:
Code:
login_lv.sendAndLoad("processLogin.php", login_lv, "POST")
Other than that I'm at a loss, and I've been working on this stupid thing all damn day. Aarrgghh!
Last edited by nunomira; 03-01-2006 at 08:11 AM.
Reason: no need to quote that much!
Rob
"hokey religions and ancient weapons are no match for a good blaster by your side, kid"
-
no difference
thanks eveyln, but it didn't seem to make much of a difference.
Last edited by nunomira; 03-01-2006 at 08:38 AM.
Reason: no need to quote that much!
Rob
"hokey religions and ancient weapons are no match for a good blaster by your side, kid"
-
Registered User
The method for flash was: no matter what the variables from flash are, you are always granted access.
This would ensure that flash was comunicating correctly.
I guess this is what a_modified_dog suggested:
Make sure that the moment you submit the variables to php, is the moment that you get the values from the input text fields (first the variables).
This means that
code:
login_lv.fuser=login_txt.text;
login_lv.fpass=password_txt.text;
// and
login_lv.sendAndLoad("processLogin.php", login_lv, "POST");
have to be all together.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|