SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Member
    Join Date
    Nov 2012
    0 Post(s)
    0 Thread(s)

    Establishing a connection to my Database in mysql

    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);
 = email.text;
    phpVars.username = username.text;
    phpVars.password = password.text;
    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 = email_txt.text;
         variables.pass = password_txt.text;
            // Send the data to the php file
            status_txt.text = "Processing...";
        } // close else after form validation
    } // Close ValidateAndSend function //////////////

    php file

    Code PHP:
    $link = mysql_connect("localhost","example","password");
    $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!
    Last edited by TechnoBear; Dec 8, 2012 at 14:13. Reason: Code tags added

  2. #2
    SitePoint Member
    Join Date
    Nov 2008
    0 Post(s)
    0 Thread(s)
    What do you mean by "they don't work"? Do you get an error message or just not the result you expected?

    The PHP code you've posted has a syntax error in it - unclosed single quote on the first line. And if you fix that, the PHP doesn't seem to be doing any checking against the variables you're (presumably) POSTing to it from the Flash script, you're just SELECTing all users in the table.

    Do you get the expected records if you run your query in a MySQL command line? Does your table actually have the data you're looking for?

  3. #3
    Keeper of the SFL StarLion's Avatar
    Join Date
    Feb 2006
    Atlanta, GA, USA
    73 Post(s)
    0 Thread(s)
    So lets see; real obvious problems in the PHP script:

    Line 7 -> $_Post => $_POST (yes, it matters)
    Line 11 -> Unclosed quote.
    Line 12 -> Missing semicolon.
    Line 17 -> Checking condition should be == 1 (Because you've made your database entries unique, correct?)
    Line 19 -> Because condition should be == 1, while is unnecessary (Should be exactly 1 record)
    Line 34 -> Closing brace without an opening brace.
    Never grow up. The instant you do, you lose all ability to imagine great things, for fear of reality crashing in.


Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts