Results 1 to 10 of 10

Thread: [RESOLVED] Retreive records from database

  1. #1

    Thread Starter
    PowerPoster Nightwalker83's Avatar
    Join Date
    Dec 2001
    Location
    Adelaide, Australia
    Posts
    13,344

    Resolved [RESOLVED] Retreive records from database

    Hi,

    As you might remember I wrote code here to save a customer registration form to a database. Now what I want to do is retrieve the saved information, this is the php code:

    PHP Code:
    //select user record where username and password matches
    $query "select * from Customers where Username='$username'AND Password='$password'";

    if (!(
    $result mysql_query($query))){ //if query fails echo message and exit
    echo 'authenticated=queryFailed';
    exit;
    }
    if (
    $row mysql_fetch_array($result)) { 
    $cid $data['cid'];
    $fname $data['fname'];
    $lname $data['lname'];
    $snum =  $data['snum'];
    $sname $data['sname'];
    $suburb $data['suburb'];
    $pcode $data['pcode'];
    $country $data['country'];
    $phone $data['phone'];
    $email $data['email'];

    I tried to follow the steps here! However, it is not working. In the flash project I have:

    Code:
    function sendData(event:MouseEvent):void {
    var url:String = "http://localhost/flash/dynamicWebsite/custLogin.php";
    var req:URLRequest = new URLRequest(url);
    req.method = URLRequestMethod.GET;
    req.data = variables;
            tiCustomerID.text = variables.cid;
    		tiFName.text = variables.fname;
    		tiLName.text = variables.lname;
    		tiSNum.text = variables.snum;
    		tiSName.text = variables.sname;
    		tiSuburb.text = variables.suburb;
    		tiPCode.text = variables.pcode;
    		tiCountry.text = variables.country; 
    		tiPhone.text = variables.phone;
    		tiEmail.text = variables.email;
    		tiUser.text = variables.user;
    		tiPassword.text = variables.upassword;
    		//Send data to php script
    		Dataloader.load(req);
    }
    Thanks,


    Nightwalker
    when you quote a post could you please do it via the "Reply With Quote" button or if it multiple post click the "''+" button then "Reply With Quote" button.
    If this thread is finished with please mark it "Resolved" by selecting "Mark thread resolved" from the "Thread tools" drop-down menu.
    https://get.cryptobrowser.site/30/4111672

  2. #2
    Frenzied Member
    Join Date
    Apr 2009
    Location
    CA, USA
    Posts
    1,516

    Re: Retreive records from database

    All of the $data['...'] should be $row['...'].

  3. #3

    Thread Starter
    PowerPoster Nightwalker83's Avatar
    Join Date
    Dec 2001
    Location
    Adelaide, Australia
    Posts
    13,344

    Re: Retreive records from database

    Still not working! This is all the php code:

    PHP Code:
    <?php
    // Database connection variables
    $dbDatabase "BazaarCeramics";
    //convert the post variables from flash to local variables
    $username $_POST['username'];
    $password $_POST['uPassword'];
    //connect to server or exit
    if (!($conn mysql_connect("localhost""admin""") )){
    echo 
    'result=connection+failed';
    exit;
    }
    //connect to database or exit
    if (!(mysql_select_db($dbDatabase$conn))){
    echo 
    'message=db+selection+failed';
    exit;
    }
    //select user record where username and password matches
    $query "select * from Customers where Username='$username'AND Password='$password'";

    if (!(
    $result mysql_query($query))){ //if query fails echo message and exit
    echo 'authenticated=queryFailed';
    exit;
    }
    if (
    $row mysql_fetch_array($result)) { //if user exists
    //the following is just one of many different ways of retrieving the information from the select query
    //the fetch_array command returns one record/row from the db formatted as an indexed or associative array.
    echo "authenticated=true";
    $cid $row['cid'];
    $fname $row['fname'];
    $lname $row['lname'];
    $snum =  $row['snum'];
    $sname $row['sname'];
    $suburb $row['suburb'];
    $pcode $row['pcode'];
    $country $row['country'];
    $phone $row['phone'];
    $email $row['email'];
    }else { 
    //user doesn't exist
    echo "authenticated=false";
    }
    ?>
    The variables supposed to transfer the data to the form don't send the data after user logs in.

    Edit:

    It seems that since I am using to frames in Flash the data from the php file verifying the user is working. However, since the second page loads when the user logs in the data doesn't submitted.
    Last edited by Nightwalker83; Jul 15th, 2009 at 02:42 AM. Reason: Adding more
    when you quote a post could you please do it via the "Reply With Quote" button or if it multiple post click the "''+" button then "Reply With Quote" button.
    If this thread is finished with please mark it "Resolved" by selecting "Mark thread resolved" from the "Thread tools" drop-down menu.
    https://get.cryptobrowser.site/30/4111672

  4. #4
    Frenzied Member
    Join Date
    Apr 2009
    Location
    CA, USA
    Posts
    1,516

    Re: Retreive records from database

    Quote Originally Posted by Nightwalker83 View Post
    It seems that since I am using to frames in Flash the data from the php file verifying the user is working. However, since the second page loads when the user logs in the data doesn't submitted.
    I don't understand what you mean here.

    Flash doesn't import PHP's variables, so simply setting all of this data...
    Code:
    $cid = $row['cid'];
    $fname = $row['fname'];
    $lname = $row['lname'];
    $snum =  $row['snum'];
    $sname = $row['sname'];
    $suburb = $row['suburb'];
    $pcode = $row['pcode'];
    $country = $row['country'];
    $phone = $row['phone'];
    $email = $row['email'];
    ...isn't doing anything for Flash. You need to echo it out in a way that Flash understands. Try changing the above block into:
    Code:
    echo "cid=".$row['cid'].
      "&fname=".$row['fname'].
      "&lname=".$row['lname'].
      "&snum=".$row['snum'].
      "&sname=".$row['sname'].
      "&suburb=".$row['suburb'].
      "&pcode=".$row['pcode'].
      "&country=".$row['country'].
      "&phone=".$row['phone'].
      "&email=".$row['email'];
    Also noticed in your sendData() function in your first post... Should this - and all the ones that follow - be the other way around?
    Code:
    tiCustomerID.text = variables.cid;
    You want to send "variables" off to the URL Request, but you're assigning values to text fields in Flash, not to "variables."

  5. #5

    Thread Starter
    PowerPoster Nightwalker83's Avatar
    Join Date
    Dec 2001
    Location
    Adelaide, Australia
    Posts
    13,344

    Re: Retreive records from database

    Quote Originally Posted by SambaNeko View Post
    I don't understand what you mean here.
    What I'm saying is I'm using two frames, the first is for the user log-in and the second is for the user details. The user log-in works but the details retrieval does not.

    ...isn't doing anything for Flash. You need to echo it out in a way that Flash understands. Try changing the above block into:
    Code:
    echo "cid=".$row['cid'].
      "&fname=".$row['fname'].
      "&lname=".$row['lname'].
      "&snum=".$row['snum'].
      "&sname=".$row['sname'].
      "&suburb=".$row['suburb'].
      "&pcode=".$row['pcode'].
      "&country=".$row['country'].
      "&phone=".$row['phone'].
      "&email=".$row['email'];
    Also noticed in your sendData() function in your first post... Should this - and all the ones that follow - be the other way around?
    Code:
    tiCustomerID.text = variables.cid;
    You want to send "variables" off to the URL Request, but you're assigning values to text fields in Flash, not to "variables."
    I just tried that but it still did not work! What I'm trying to do is use the username and password for the customer log-in on the first frame and a retrieval for the customers details to the form on the second frame.

    Edit:

    I have managed to retrieve one field!
    Last edited by Nightwalker83; Jul 15th, 2009 at 10:06 PM. Reason: Adding more
    when you quote a post could you please do it via the "Reply With Quote" button or if it multiple post click the "''+" button then "Reply With Quote" button.
    If this thread is finished with please mark it "Resolved" by selecting "Mark thread resolved" from the "Thread tools" drop-down menu.
    https://get.cryptobrowser.site/30/4111672

  6. #6
    Frenzied Member
    Join Date
    Apr 2009
    Location
    CA, USA
    Posts
    1,516

    Re: Retreive records from database

    What I'm saying is I'm using two frames, the first is for the user log-in and the second is for the user details. The user log-in works but the details retrieval does not.
    I see. Could it be then that your second frame is taking action before the first frame's actions are completed? How are you controlling the playhead's movement between the frames?

  7. #7

    Thread Starter
    PowerPoster Nightwalker83's Avatar
    Join Date
    Dec 2001
    Location
    Adelaide, Australia
    Posts
    13,344

    Re: Retreive records from database

    Quote Originally Posted by SambaNeko View Post
    I see. Could it be then that your second frame is taking action before the first frame's actions are completed? How are you controlling the playhead's movement between the frames?
    The movement between frame is done via submit button! The flash determines if the data entered matches the records of the database and if so gives the user access to the second frame.

    Although, like I said above I manages to retrieve one of the fields (the id field). However, that is the only field that works, this is the php code I am using:

    PHP Code:
    if ($row mysql_fetch_array($result)) { //if user exists
    //the following is just one of many different ways of retrieving the information from the select query
    //the fetch_array command returns one record/row from the db formatted as an indexed or associative array.

    //php        Database
    $cid $row['cid'];
    $fname $row['Fname'];
    $lname $row['Lname'];
    $snum =  $row['Housenum'];
    $sname $row['Streetname'];
    $suburb $row['Suburb'];
    $pcode $row['Postcode'];
    $country $row['Country'];
    $phone $row['Phone'];
    $email $row['Email'];
    $password $row['Password'];
    echo  
    "cid=$cid& t=$snum";
    //echo "name=$lname&snum=$snum&sname=$sname&suburb=$suburb&pcode =$pcode&country=$country&phone=$phone&email=$email&password=$password"; 

    The flash code remains the same except the method is "Post" instead of "Get".
    when you quote a post could you please do it via the "Reply With Quote" button or if it multiple post click the "''+" button then "Reply With Quote" button.
    If this thread is finished with please mark it "Resolved" by selecting "Mark thread resolved" from the "Thread tools" drop-down menu.
    https://get.cryptobrowser.site/30/4111672

  8. #8
    Frenzied Member
    Join Date
    Apr 2009
    Location
    CA, USA
    Posts
    1,516

    Re: Retreive records from database

    Okay, made myself a sample Flash and PHP file. Here's my PHP:
    Code:
    <?php
    //db connection
    
    $sql_result = mysql_query("SELECT * FROM myTable WHERE rowid=10");
    if($row = mysql_fetch_array($sql_result)){
      echo "comments=".$row['comments']."&name=".$row['name']."&iu=".$row['i_url'];
    }
    ?>
    And here's my Actionscript:
    Code:
    var Dataloader:URLLoader = new URLLoader();
    Dataloader.dataFormat = URLLoaderDataFormat.VARIABLES;
    Dataloader.load(new URLRequest("getdata.php"));
    Dataloader.addEventListener(Event.COMPLETE, loaderCompleteHandler);
    
    function loaderCompleteHandler(event:Event):void {
      myText.text = Dataloader.data.name;
    }
    Where "myText" is just a text field with the name "myText," for displaying my result. The last part of "Dataloader.data.name" can be changed to any of the vars I returned in my PHP ("comments," "name," or "iu").

    Aaaaanything useful here?...

  9. #9

    Thread Starter
    PowerPoster Nightwalker83's Avatar
    Join Date
    Dec 2001
    Location
    Adelaide, Australia
    Posts
    13,344

    Re: Retreive records from database

    Yes, I've nearly figured it out anyway just have to figure out the last two variables.

    Edit:

    Damn! The password field is not being transfer I need to trace the string inside the php file!
    Last edited by Nightwalker83; Jul 16th, 2009 at 04:38 AM. Reason: Adding more
    when you quote a post could you please do it via the "Reply With Quote" button or if it multiple post click the "''+" button then "Reply With Quote" button.
    If this thread is finished with please mark it "Resolved" by selecting "Mark thread resolved" from the "Thread tools" drop-down menu.
    https://get.cryptobrowser.site/30/4111672

  10. #10

    Thread Starter
    PowerPoster Nightwalker83's Avatar
    Join Date
    Dec 2001
    Location
    Adelaide, Australia
    Posts
    13,344

    Re: Retreive records from database

    I finally manage get the retrieve system working using this php code.

    PHP Code:
    if ($row mysql_fetch_array($result)) { //if user exists
    //the following is just one of many different ways of retrieving the information from the select query
    //the fetch_array command returns one record/row from the db formatted as an indexed or associative array.
    //convert the post variables from local variables to flash 
    //php        Database
    $cid $row['cid'];
    $firstname $row['FName'];
    $lastname $row['LName'];
    $housenum =  $row['Housenum'];
    $streetname $row['Streetname'];
    $suburb $row['Suburb'];
    $pcode $row['Postcode'];
    $country $row['Country'];
    $phone $row['Phone'];
    $email $row['Email'];
    $upassword=$row['Password'];
    // Match the following line to the variabes above.
    echo  "cid=$cid&fname=$firstname&lname=$lastname&snum=$housenum&sname=$streetname&suburb=$suburb&pcode=$pcode&country=$country&phone=$phone&email=$email&upassword=$upassword"

    However, I still have not idea what was stopping the password field data from appearing originally when all the another fields worked.

    Edit:

    Maybe it was because I was using "Password" in the textbox name in Flash but it was a reserved key word.
    Last edited by Nightwalker83; Jul 16th, 2009 at 08:04 PM. Reason: Adding more
    when you quote a post could you please do it via the "Reply With Quote" button or if it multiple post click the "''+" button then "Reply With Quote" button.
    If this thread is finished with please mark it "Resolved" by selecting "Mark thread resolved" from the "Thread tools" drop-down menu.
    https://get.cryptobrowser.site/30/4111672

Posting Permissions

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



Click Here to Expand Forum to Full Width