sleazyfish Posted October 27, 2010 Share Posted October 27, 2010 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 Quote Link to comment Share on other sites More sharing options...
sleazyfish Posted October 27, 2010 Author Share Posted October 27, 2010 oh and mysql is 5.0.91 Quote Link to comment Share on other sites More sharing options...
Pikachu2000 Posted October 28, 2010 Share Posted October 28, 2010 In what way is it not working? Quote Link to comment Share on other sites More sharing options...
sleazyfish Posted October 28, 2010 Author Share Posted October 28, 2010 I'm getting a "wrong user and/or password" error message that is set up on a dynamic text box in flash. As i say it works fine from flash just not when posted online. Quote Link to comment Share on other sites More sharing options...
gizmola Posted October 28, 2010 Share Posted October 28, 2010 At the risk of pointing out the obvious, one script gets its input from a POST (the problem one) and the one that works gets its input from a GET. Is your flash movie form.loadVariables() call would need to specify "POST" as the method. Quote Link to comment Share on other sites More sharing options...
sleazyfish Posted October 28, 2010 Author Share Posted October 28, 2010 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(); } Quote Link to comment Share on other sites More sharing options...
sleazyfish Posted October 28, 2010 Author Share Posted October 28, 2010 just to make things clear the one that works uses actionscript on a different frame using GET. Quote Link to comment Share on other sites More sharing options...
Anti-Moronic Posted October 28, 2010 Share Posted October 28, 2010 I'm sorry I can't help on your issue, but just in case nobody points this out: "assumed get would mean get and post would mean send" They both mean 'send', they are just different methods of sending data. See here: http://www.plus2net.com/asp-tutorial/form-diff.php Quote Link to comment Share on other sites More sharing options...
sleazyfish Posted October 28, 2010 Author Share Posted October 28, 2010 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. Quote Link to comment Share on other sites More sharing options...
sleazyfish Posted October 28, 2010 Author Share Posted October 28, 2010 turns out it was aproblem in the actionscript not the PHP. Thanks for your help anyway. I'm sure i'll need more soon Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.