Hello, I recently built my first database in phpMyAdmin. I really find this fascinating. My table has id, username, password and age in columns.
In Flash CS6 i have an as3 file. In notepad i have a php file. I am trying to connect my Flash login system to mysql database through php to create a login system in Flash.
I have tested both files and there not working. I am using a login function in flash that sends the username/password/ages variables to the PHP script. the PHP script is then checking that those variables are stored in the database.
Here is the code that i am using:
ActionScript 3
Code Actionscript://Requesting the php var phpFileRequest: URLRequest = new URLRequest("http://localhost"); phpFileRequest.method = URLRequestMethod.POST; //Assing the variable names //Build the variable var phpVars:URLVariables = new URLVariables(); //Building the loader var phpLoader:URLLoader = new URLLoader(); var phpLoader = dateFormat.URLLOADERDATEFORMAT.VARIABLES; phpLoader.addEventListener(Event.COMPLETE, showResult); phpVars.email = email.text; phpVars.username = username.text; phpVars.password = password.text; phpLoader.load(phpFileRequest); phpLoader.addEventListener(Event.COMPLETE, showResult); // Add an event listener for the submit button and what function to run submit_btn.addEventListener(MouseEvent.CLICK, ValidateAndSend); // Validate form fields and send the variables when submit button is clicked function ValidateAndSend(event:MouseEvent):void{ status_txt.text =""; //validate form fields if(!email_txt.length) { status_txt.text = "Please enter your email address."; } else if(!password_txt.length) { status_txt.text = "Please enter your password."; } else { // Ready the variables for sending variables.email = email_txt.text; variables.pass = password_txt.text; // Send the data to the php file varLoader.load(varSend); status_txt.text = "Processing..."; } // close else after form validation } // Close ValidateAndSend function //////////////
php file
Code PHP:<?php $link = mysql_connect("localhost","example","password"); mysql_select_db("example_users"); $email = $_Post['email']; $username = $_POST['username']; $password = $_POST['password']; $query = 'SELECT * FROM users; $results = mysql_query($query) $login_counter = mysql_num_rows($query); if ($login_counter > 0) { while ($data = mysql_fetch_array($query)) { $userbio = $data["name"]; echo "systemResult=$userbio"; } } else { echo "systemResult=The login details dont match our records."; } } ?>
Any help on what could be going wrong would be great!


Reply With Quote

Bookmarks