Jump to content

mysql to php to flash AS2 and visa versa


sleazyfish

Recommended Posts

Hi,

I'm very new to PHP and i'm trying to delevop an app using flash as the front end via PHP and  a mySQL database on my server/host.

 

I currently have two php scripts that I am referencing. The first is used as a login and the second is used to retrieve table data. Both scripts work fine when tested in flash but when I upload the flash file to my server and test online the first (login) refuses to work. The php files are already uploaded to the server and the mySql database is created on my server.

 

I was wondering if there was anything in the script that might be causing this. I can't see why and my brain is starting to degrade rapidly.

 

Can someone have a quick look and tell me if there's something in this script that's preventing this from working online please?

 

my flash variables are: user and pass

 

This is the login script that won't work online:

 

<?
//this pulls the variables from the flash movie when the user
//hits submit.  Use this when your global variables are off.
//I don't know how to toggle global variables, so I just put
//it in all the time 

$user=$_POST['user'];
$pass=$_POST['pass'];


//connect to database

mysql_pconnect("*****","********","******") or die ("didn't connect to mysql");
mysql_select_db("******") or die ("no database");
//make query
$query = "SELECT * FROM jingle WHERE recipient = '$user' AND password = '$pass' ";
$result = mysql_query( $query ) or die ("didn't query");

//see if there's an EXACT match
$num = mysql_num_rows( $result );

if ($num >=1){
print "status=You're in&checklog=1";
} else {
print "status=Sorry, but your user name and password did not match a user name/password combination in our database.  Usernames and passwords are entered in from a different file.  Thank you for visiting test login script!!&checklog=2";

}

?>

 

 

and this is the script the does work online:

 

<?
/*
    Retrieves score data from highscores table and returns 
                  data and status to Flash
   
   errorcode:
      0: successful select
      1: can't connect to server
      2: can't connect to database
      3: can't run query
*/

//  fill this in with the right data for your server/database config
$server = "*****";
$username = "******";
$password = "******";
$database = "*******";


// get current user

$user=$_GET['user'];
$pass=$_GET['pass'];


//  mysql_connect: Open a connection to a MySQL Server
//  Returns a MySQL link identifier on success, or FALSE on failure.
if (!mysql_connect($server, $username, $password)) {
   $r_string = '&errorcode=1&';	

//  mysql_select_db: Sets the current active database on the server that's associated 
//    with the specified link identifier. Every subsequent call to mysql_query() 
//    will be made on the active database.
//  Returns TRUE on success or FALSE on failure.
} elseif (!mysql_select_db($database)) {
   $r_string = '&errorcode=2&';

//  mysql_query: Sends a query (to the currently active database
//  For SELECT, SHOW, DESCRIBE or EXPLAIN statements, mysql_query() returns a 
//     resource on success, or FALSE on error.  
//  For other type of SQL statements, UPDATE, DELETE, DROP, etc, mysql_query() 
//     returns TRUE on success or FALSE on error. 
} else {
   $qr = mysql_query("SELECT * from jingle WHERE recipient = '$user' AND password = '$pass'");
   if (!qr || mysql_num_rows($qr)==0) {
      $r_string = '&errorcode=3&msg='.mysql_error().'&';
   } else {
      $r_string = '&errorcode=0&n='.mysql_num_rows ($qr);
      $i = 0;
      while ($row = mysql_fetch_assoc ($qr)) {
         while (list ($key, $val) = each ($row)) {
            $r_string .= '&' . $key . $i . '=' . stripslashes($val);
         }
         $i++;
      }
      // add extra & to prevent returning extra chars at the end
      $r_string .='&';
   }
}
echo $r_string;
?>

 

Thanks in advance

Link to comment
Share on other sites

hi, i have tried both GET and POST (although i don't really understand the different I assumed get would mean get and post would mean send).

 

 

This is  my actionscript i'm using the sendAndLoad method:

 

stop();

Stage.scaleMode = "noScale"

status = 'please login and hit submit';
// create two new instances of LoadVars, one to send and one to receive data
var dataOut:LoadVars = new LoadVars();
var dataIn:LoadVars = new LoadVars();

// define what should happen when the response is received,
// using 'this' to refer to dataIn and get data from it
dataIn.onLoad = function() {
   if (dataIn.checklog=="1") {
       status = 'Logging in - please wait';
      gotoAndStop(2);
   } else {
      status = 'Wrong user and/or password';
   }
}

// the function that will be called by the Enter button 
function checkUser():Void {
   dataOut.user = user;
   dataOut.pass = pass;

   dataOut.sendAndLoad("*******.php", dataIn, "POST");
}

// define the behavior of the Enter button
submitButton.onRelease=function(){
    status = " Logging In - Please Wait...";
    checkUser();
}

 

 

Link to comment
Share on other sites

thanks for the link that cleared the misunderstanding up.

 

Although if anyone could point me in the right direction i'd be most appreciative.

can anyone see why the php won't work online? do you think that this is an issue i have with my AS2 script?

 

any opinions would be welcome.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.