Donbudz Posted November 12, 2008 Share Posted November 12, 2008 Hi all, Not sure how to ask this, hope im posting in the right place. I am looking for a simple way to have flash constantly answer a PHP file. When PHP doesnt receive answer from flash MC(like if swf is unloaded or closed), then I want PHP to run a Mysql query. I dont need anything visually. Just a script running in background keeping a constant communication with php file. Thnks for any help on this matter. Peace out Quote Link to comment Share on other sites More sharing options...
rarebit Posted November 12, 2008 Share Posted November 12, 2008 Where are you stuck? 'ave you got a start? Quote Link to comment Share on other sites More sharing options...
Donbudz Posted November 12, 2008 Author Share Posted November 12, 2008 I have a login.swf, first frame has this code: published in "flash cs3": //Button Functions signupBtn.onRelease = function() { _parent.gotoAndStop("register"); }; forgotpwBtn.onRelease = function() { _parent.gotoAndStop("forgotPW"); }; status_txt.text = ""; status_txt2.text = ""; status_txt.autoSize = false; status_txt2.autoSize = false; //Variables to handle PHP var dataOut:LoadVars = new LoadVars(); var dataIn:LoadVars = new LoadVars(); //Run this function when Flash receives something back from PHP dataIn.onLoad = function() { loginBtn.enabled = true; var responsetext = this.msgText; var whoUser = this.userName; var fName = this.fName; var lName = this.lName; var phone = this.phone; var email = this.email; var address = this.address; var city = this.city; var state = this.state; var zip = this.zip; status_txt.text = responsetext; status_txt2.text = responsetext; //If the username and password matches do the following if (responsetext == "Entrance Granted!") { //Set global variables so these can be access across any frame _global.person = whoUser; _global.fName = fName; _global.lName = lName; _global.emailadd = email; _global.phoneNum = phone; _global.addy = address; _global.cityy = city; _global.state = state; _global.zip = zip; //go to the secure area. _parent.gotoAndStop("protected"); } }; //When you hit login run this function. loginBtn.onRelease = function() { //check if any of the fields are empty if (username.text == "" || password.text == "") { status_txt.text = "Please fill in all fields."; status_txt2.text = "Please fill in all fields."; } else { //if they are not empty, send the username and password to login.php and wait for a response. (The onLoad up top runs once PHP sends back to flash) loginBtn.enabled = false; status_txt.text = "Checking username & password..."; status_txt2.text = "Checking username & password..."; dataOut.username = username.text; dataOut.password = password.text; //this last sendAndLoad function is what talks to the PHP file. dataOut.sendAndLoad(loginLocation,dataIn,"POST"); } }; //Same as above, just adds functionality to the enter key. var keyObj:Object = new Object(); keyObj.onKeyDown = function() { if (Key.getCode() == Key.ENTER) { if (username.text == "" || password.text == "") { status_txt.text = "Please fill in all fields."; status_txt2.text = "Please fill in all fields."; } else { loginBtn.enabled = false; status_txt.text = "Checking username & password..."; status_txt2.text = "Checking username & password..."; dataOut.username = username.text; dataOut.password = password.text; dataOut.sendAndLoad(loginLocation,dataIn,"POST"); } } }; Key.addListener(keyObj); The PHP this is talking to is: <?php include "connect.php"; $tableName = "usersv2"; $tableName2 = "users_online"; $username = $_POST['username']; $password = md5($_POST['password']); $sql = mysql_query("SELECT * FROM $tableName WHERE username = '$username' and password = '$password'"); $rows = mysql_num_rows($sql); $arr = mysql_fetch_array($sql); $fname = $arr[3]; $lname = $arr[4]; $user = $arr[1]; $email = $arr[5]; $phone = $arr[6]; $address = $arr[7]; $city = $arr[8]; $state = $arr[9]; $zip = $arr[10]; if($rows == 1) { echo "&msgText=Entrance Granted!"; echo "&whosIn=$fname $lname"; echo "&fName=$fname"; echo "&lName=$lname"; echo "&userName=$user"; echo "&email=$email"; echo "&phone=$phone"; echo "&address=$address"; echo "&city=$city"; echo "&state=$state"; echo "&zip=$zip"; $insert = mysql_query("INSERT INTO $tableName2 (usersonline) VALUES ('$username')") or die(mysql_error()); } else { echo "&msgText=Invalid Login!"; } ?> i added a line into this PHP script: $insert = mysql_query("INSERT INTO $tableName2 (usersonline) VALUES ('$username')") or die(mysql_error()); What i want to do is add a code to flash and php in order for php to know when flash stops answering PHP will then run a query: mysql_query("DELETE FROM $tableName2 WHERE useronline = $username"); so flash needs to constantly tell PHP its still open, like a loop in flash that keeps sending php a variable or something. When PHP no longer receives that variable PHP will then run the DELETE query. Hope u understand all that. I am a noob at alot of this. Thank for anyhelp, peace Quote Link to comment Share on other sites More sharing options...
genericnumber1 Posted November 12, 2008 Share Posted November 12, 2008 I would more suggest programming for socket connections as opposed to a constant pinging of the server. See: http://us2.php.net/manual/en/ref.stream.php Quote Link to comment Share on other sites More sharing options...
Donbudz Posted November 13, 2008 Author Share Posted November 13, 2008 Even if i just want, lets say an interval of 5 seconds, to send variable to php? i just want to display user that is logged in, and dump the name when user logs out. Quote Link to comment Share on other sites More sharing options...
genericnumber1 Posted November 13, 2008 Share Posted November 13, 2008 You can, theoretically, do it either way. I suggested the way I would do it. Quote Link to comment Share on other sites More sharing options...
Donbudz Posted November 13, 2008 Author Share Posted November 13, 2008 ya.. i would prefer to learn some xml socket programing... but I would need some sort of example or tutorial that i can learn from. Dont know where to begin searching for what i need. I normally learn from examples. The link you provided is like a needle in a haystack for me. If you cant help me implement a socket. Can u help me run the DELETE query from my last frame in MC? I can get it to INSERT in my first frame. But DELETE on last frame is not working for me. Quote Link to comment Share on other sites More sharing options...
Donbudz Posted November 13, 2008 Author Share Posted November 13, 2008 My DELETE query is not working at all. mysql_query("DELETE FROM $tableName2 WHERE $fieldname = $username"); failed to delete row However this DELETE query works for deleting all rows in the table: mysql_query("DELETE FROM $tableName2"); success deleted all rows Seems im having problems when i add the condition/WHERE statement. I have also tried: mysql_query("DELETE FROM $tableName2 WHERE $fieldname"); failed to delete row This is my PHP: <?php include "connect.php"; $tableName2 = "users_online"; $username = "donbudz"; $fieldname = "usersonline"; mysql_query("DELETE FROM $tableName2 WHERE $fieldname = $username"); ?> Here is the query i created the table with: DROP TABLE IF EXISTS users_online; CREATE TABLE users_online ( usersonline char(15) NOT NULL default '') TYPE=MyISAM; Why cant this query delete the one row? Quote Link to comment Share on other sites More sharing options...
iversonm Posted November 13, 2008 Share Posted November 13, 2008 your delete should have '' around the username like this mysql_query("DELETE FROM $tableName2 WHERE $fieldname = '$username'"); Quote Link to comment Share on other sites More sharing options...
Donbudz Posted November 13, 2008 Author Share Posted November 13, 2008 ..sorry i was editing while your were reading.. i will try ' ' let ya know how it goes. Quote Link to comment Share on other sites More sharing options...
Donbudz Posted November 13, 2008 Author Share Posted November 13, 2008 YES! that was my problem with the DELETE query. Now if you dont mind... I want flash to run this PHP file in a frame action. Using Flash CS3. Quote Link to comment Share on other sites More sharing options...
Donbudz Posted November 13, 2008 Author Share Posted November 13, 2008 I got frame action to work on my own... sorry, for answering my own question. But for the forums sake here was my frame action to run the PHP i posted: loadVariablesNum("http://www.somesite.com/somepage.php", 2, "POST"); I have one more thing to try to get to work in this whole DELETE query, and that is the DELETE query calling VALUE from a text field and deleting that row. Quote Link to comment Share on other sites More sharing options...
Donbudz Posted November 13, 2008 Author Share Posted November 13, 2008 OK.. Got this to work right!! In my PHP i just had to change the code to match variable name of my text field on that frame. $username = $_POST['useronline']; where 'useronline' is my textfield variable name. So here is a quick summary of what i done here: INSERT text that user enters into username field into database: $insert = mysql_query("INSERT INTO $tableName2 (usersonline) VALUES ('$username')") or die(mysql_error()); Then DELETE that entry from database on last frame of MC. mysql_query("DELETE FROM $tableName2 WHERE $fieldname = '$username'"); this is probably confusing to someone else because of INSERT and DELETE are in different frames in MC. And they have different variable names. Anyways thanks for the help from you all... later, peace out (solved) Quote Link to comment Share on other sites More sharing options...
Donbudz Posted November 13, 2008 Author Share Posted November 13, 2008 I got frame action to work on my own... sorry, for answering my own question. But for the forums sake here was my frame action to run the PHP i posted: loadVariablesNum("http://www.mysite.com/logoff.php", 2, "POST"); I have one more thing to try to get to work in this whole DELETE query, and that is the DELETE query calling VALUE from a text field and deleting that row. Wanting to DELETE my address to PHP file........... 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.