0 Replies Latest reply on Mar 25, 2007 2:05 PM by portuguesedanny

    Search particular record in db

    portuguesedanny
      Apologies for submiting 3 times... Everytime I hit 'Submit Message' I got a timeout..!

      Hi all,

      I am using the code below, but I want to add the ability to search the db for a particular record.
      Could someone suggest some possible methods (as I'm a newbie to Flex/AS/Php, albeit a seasoned network admin) :)

      TIA
      Danny


      mxml file
      <?xml version="1.0" encoding="utf-8"?>
      <mx:Application xmlns:mx=" http://www.adobe.com/2006/mxml" layout="absolute"
      xmlns="*" creationComplete="send_data()">

      <mx:Script>
      <![CDATA[
      private function send_data():void {
      userRequest.send();
      }
      ]]>
      </mx:Script>

      <mx:Form x="22" y="10" width="493">
      <mx:HBox>
      <mx:Label text="Username"/>
      <mx:TextInput id="username"/>
      </mx:HBox>
      <mx:HBox>
      <mx:Label text="Email Address"/>
      <mx:TextInput id="emailaddress"/>
      </mx:HBox>
      <mx:Button label="Submit" click="send_data()"/>
      </mx:Form>
      <mx:DataGrid id="dgUserRequest" x="22" y="128" dataProvider="{userRequest.lastResult.users.user}">
      <mx:columns>
      <mx:DataGridColumn headerText="User ID" dataField="userid"/>
      <mx:DataGridColumn headerText="User Name" dataField="username"/>
      </mx:columns>
      </mx:DataGrid>
      <mx:TextInput x="22" y="292" id="selectedemailaddress"
      text="{dgUserRequest.selectedItem.emailaddress}"/>

      <mx:HTTPService id="userRequest" url=" http://localhost/flex/php/request.php" useProxy="false" method="POST">
      <mx:request xmlns="">
      <username>{username.text}</username><emailaddress>{emailaddress.text}</emailaddress>
      </mx:request>
      </mx:HTTPService>
      </mx:Application>

      php file

      <?php

      $host="localhost";
      $username="root";
      $password="design";
      $db_name="sample";

      //connect to the database
      mysql_connect("$host", "$username", "$password")or die("cannot connect to server");
      mysql_select_db("$db_name")or die("cannot select db");

      //if the username and email address are filled out
      if( $_POST["emailaddress"] AND $_POST["username"])
      {
      //add the user
      $Query = "INSERT INTO users VALUES ('', '".$_POST['username']."', '".$_POST['emailaddress']."')";

      $Result = mysql_query( $Query );
      }

      //return a list of all the users
      $Query = "SELECT * from users";
      $Result = mysql_query( $Query );

      $Return = "<users>";

      while ( $User = mysql_fetch_object( $Result ) )
      {
      $Return .= "<user><userid>".$User->userid."</userid><username>".$User->username."</username><emailad dress>".$User->emailaddress."</emailaddress></user>";
      }
      $Return .= "</users>";
      mysql_free_result( $Result );
      print ($Return)
      ?>