4 Replies Latest reply on Nov 16, 2011 5:32 PM by pierre.rodrigue

    Flex spark dropdownlist to mySQL using php

    bertg1jm

      Hello. I am creating a flex app that uses php to populate several spark dropdownlists with strings from a mySQL database. The application is a MLB playoff bracket that allows the user to select their desired winners. Inside of a panel are text input boxes that ask for name and email address from the user. The submit button then calls a method called addNewUser(). I am having a very difficult time sending the selectedItem from each dropdownlist and the username and email to the database. I am able to add just the username into the database.  the table layout in the database is (user_id, user_name, email, alds_winner, alwcds_winner, nlds_winner, nlwcdc_winner, alcs_winner, nlcs_winner, ws_winner). As of now, Im just sending the user_name, email, and the nlds select from dropdownlist7 to the database as alds_winner. Ive tried so many things and am just confused on why its not working. The alert box that pops up on submit button click does display nldsSelect1 as "Twins" or whatever dropdownlist7 selectedItem is. Thanks for any help.

       

      PHP: newUser.php

      <?php
          $hostname_conn = "localhost";
          $username_conn = "admin";
          $password_conn = "admin";

       

          $conn = mysql_connect($hostname_conn, $username_conn, $password_conn);

       

          mysql_select_db("mlb_playoff_db");

       

          //mysql_real_escape_string POST'ed data for security purposes
          $newuser = mysql_real_escape_string($_POST["newuser"]);
          $newemail = mysql_real_escape_string($_POST["newemail"]);
          $nldsselect = mysql_real_escape_string($_POST["nldsselect"]);


          $sql = "INSERT INTO logins (user_name,email, alds_winner) VALUES ('$newuser', '$newemail', '$nldsselect')";
         
          if (!mysql_query($sql, $conn))
          {
              echo "<status>Failed adding new user</status>";
          }
          else
          {
              echo "<status>New user added!</status>";
          }
      ?>

       

      mlb_playoff screenshot

      bracketSS.jpg

      MXML: mlb_playoffs.mxml

      <?xml version="1.0" encoding="utf-8"?>
      <s:Application xmlns:fx="http://ns.adobe.com/mxml/2009"
                     xmlns:s="library://ns.adobe.com/flex/spark"
                     xmlns:mx="library://ns.adobe.com/flex/mx" minWidth="955" minHeight="600" backgroundColor="#07002A"  xmlns:teamsservice2="services.teamsservice2.*" viewSourceURL="srcview/index.html">
          <fx:Script>
              <![CDATA[
                  import com.adobe.serializers.utility.TypeUtility;
                 
                  import mx.controls.Alert;
                  import mx.controls.Text;
                  import mx.events.FlexEvent;
                  import mx.rpc.events.ResultEvent;           
                  import spark.components.*;
                  import spark.components.supportClasses.DropDownController;
                  import spark.events.*;
                 
                  [Bindable]
                  public var newUsername:String;
                  [Bindable]
                  public var newEmail:String;
                  [Bindable]
                  public var nldsSelect1:String;
                  [Bindable]
                  public var dataDump:String = "dataDump";
                  protected function addNewUser():void
                  {
                      newUsername = newUserTxt.text;
                      newEmail = newEmailTxt.text;
                      nldsSelect1 = dropDownList7.labelDisplay.text;           
                      newUserTxt.text = "";
                      newEmailTxt.text = "";
                      Alert.show("DropDownList item selected: " + nldsSelect1);               
                      newUser.send();
                  }
                 
                  private function newUserResult(evt:ResultEvent):void
                  {
                      Alert.show(evt.result.status, "Result");
                      //getUsers.send();
                  }
                  protected function dropDownList_creationCompleteHandler(event:FlexEvent):void
                  {
                     
                      getTeamsByIDResult.token = teamsService2.getTeamsByID(1);
                  }
                 
                 
                  protected function dropDownList2_creationCompleteHandler(event:FlexEvent):void
                  {
                      getTeamsByIDResult2.token = teamsService2.getTeamsByID(2);
                  }
                 
                 
                  protected function label2_creationCompleteHandler(event:FlexEvent):void
                  {
                      getTeamsByIDResult3.token = teamsService2.getTeamsByID(1);
                  }
                 
                 
                  protected function label3_creationCompleteHandler(event:FlexEvent):void
                  {
                      getTeamsByIDResult4.token = teamsService2.getTeamsByID(2);
                  }
                  protected function label4_creationCompleteHandler(event:FlexEvent):void
                  {
                      getTeamsByIDResult5.token = teamsService2.getTeamsByID(3);
                  }
                  protected function label5_creationCompleteHandler(event:FlexEvent):void
                  {
                      getTeamsByIDResult6.token = teamsService2.getTeamsByID(4);
                  }
                  protected function label6_creationCompleteHandler(event:FlexEvent):void
                  {
                      getTeamsByIDResult7.token = teamsService2.getTeamsByID(5);
                  }
                  protected function label7_creationCompleteHandler(event:FlexEvent):void
                  {
                      getTeamsByIDResult8.token = teamsService2.getTeamsByID(6);
                  }
                  protected function label8_creationCompleteHandler(event:FlexEvent):void
                  {
                      getTeamsByIDResult9.token = teamsService2.getTeamsByID(7);
                  }
                  protected function label9_creationCompleteHandler(event:FlexEvent):void
                  {
                      getTeamsByIDResult10.token = teamsService2.getTeamsByID(8);
                  }
                 
                 
                  protected function dropDownList3_creationCompleteHandler(event:FlexEvent):void
                  {
                      getTeamsByIDResult11.token = teamsService2.getTeamsByID(3);
                  }
                 
                 
                  protected function dropDownList5_creationCompleteHandler(event:FlexEvent):void
                  {
                      getTeamsByIDResult12.token = teamsService2.getTeamsByID(5);
                  }
                 
                 
                  protected function dropDownList4_creationCompleteHandler(event:FlexEvent):void
                  {
                      getTeamsByIDResult13.token = teamsService2.getTeamsByID(4);
                  }
                 
                 
                  protected function dropDownList6_creationCompleteHandler(event:FlexEvent):void
                  {
                     
                      getTeamsByIDResult15.token = teamsService2.getTeamsByID(6);
                     
                  }
                 
                 
                  protected function dropDownList7_creationCompleteHandler(event:FlexEvent):void
                  {
                      getTeamsByIDResult17.token = teamsService2.getTeamsByID(7);
                  }
                 
                 
                  protected function dropDownList8_creationCompleteHandler(event:FlexEvent):void
                  {
                      getTeamsByIDResult18.token = teamsService2.getTeamsByID(8);
                  }
                 
                 
             
                 
                 
                  /* protected function dropDownList9_creationCompleteHandler(event:FlexEvent):void
                  {
                      getTeamsByDivID.token = teamsService2.getTeamsByDivID(1);
                     
                  } */
                 
                 
                  protected function dropDownList9_creationCompleteHandler(event:FlexEvent):void
                  {
                      getTeamsByDivIDResult.token = teamsService2.getTeamsByDivID(1);
                  }
                 
                 
             
                 
                 
                  protected function dropDownList10_creationCompleteHandler(event:FlexEvent):void
                  {
                      getTeamsByDivIDResult2.token = teamsService2.getTeamsByDivID(2);
                  }
                 
                 
                  protected function dropDownList11_creationCompleteHandler(event:FlexEvent):void
                  {
                      getTeamsByLeagueIDResult.token = teamsService2.getTeamsByLeagueID(1);
                  }
                  protected function dropDownList12_creationCompleteHandler(event:FlexEvent):void
                  {
                      getTeamsByDivIDResult4.token = teamsService2.getTeamsByDivID(3);
                  }
                  protected function dropDownList13_creationCompleteHandler(event:FlexEvent):void
                  {
                      getTeamsByDivIDResult5.token = teamsService2.getTeamsByDivID(4);
                  }
                 
                 
                  protected function dropDownList14_creationCompleteHandler(event:FlexEvent):void
                  {
                      getTeamsByLeagueIDResult2.token = teamsService2.getTeamsByLeagueID(2);
                  }
                 
                 
                  protected function dropDownList15_creationCompleteHandler(event:FlexEvent):void
                  {
                      getAllTeamsResult4.token = teamsService2.getAllTeams();   
                  }
              ]]>
          </fx:Script>
          <fx:Declarations>
             
              <s:CallResponder id="getTeamsByIDResult"/>
              <teamsservice2:TeamsService2 id="teamsService2" fault="Alert.show(event.fault.faultString + '\n' + event.fault.faultDetail)" showBusyCursor="true"/>
              <s:CallResponder id="getTeamsByIDResult2"/>
              <s:CallResponder id="getTeamsByIDResult3"/>
              <s:CallResponder id="getTeamsByIDResult4"/>
              <s:CallResponder id="getTeamsByIDResult5"/>
              <s:CallResponder id="getTeamsByIDResult6"/>
              <s:CallResponder id="getTeamsByIDResult7"/>
              <s:CallResponder id="getTeamsByIDResult8"/>
              <s:CallResponder id="getTeamsByIDResult9"/>
              <s:CallResponder id="getTeamsByIDResult10"/>
              <s:CallResponder id="getTeamsByIDResult11"/>
              <s:CallResponder id="getTeamsByIDResult12"/>
              <s:CallResponder id="getTeamsByIDResult13"/>
              <s:CallResponder id="getTeamsByIDResult14"/>
              <s:CallResponder id="getTeamsByIDResult15"/>
              <s:CallResponder id="getTeamsByIDResult16"/>
              <s:CallResponder id="getTeamsByIDResult17"/>
              <s:CallResponder id="getTeamsByIDResult18"/>
              <s:CallResponder id="getAllTeamsResult"/>
              <s:CallResponder id="getTeamsByDivID"/>
              <s:CallResponder id="getAllTeamsResult2"/>
              <s:CallResponder id="getTeamsByDivIDResult"/>
              <s:CallResponder id="getTeamsByDivIDResult2"/>
              <s:CallResponder id="getTeamsByDivIDResult3"/>
              <s:CallResponder id="getTeamsByDivIDResult4"/>
              <s:CallResponder id="getTeamsByDivIDResult5"/>
              <s:CallResponder id="getTeamsByIDResult19"/>
              <s:CallResponder id="getTeamsByIDResult20"/>
              <s:CallResponder id="getAllTeamsResult3"/>
              <s:CallResponder id="getTeamsByLeagueIDResult"/>
              <s:CallResponder id="getTeamsByLeagueIDResult2"/>
              <s:CallResponder id="getAllTeamsResult4"/>
              <mx:HTTPService id="newUser" url="newUser.php" method="POST" result="newUserResult(event)">
                  <mx:request xmlns="">
                      <newuser>{newUsername}</newuser>
                      <newuser>{newEmail}</newuser>
                      <nldsselect>{nldsSelect1}</nldsselect>
                  </mx:request>               
              </mx:HTTPService> 
             
              <s:CallResponder id="updateTeamsResult"/>
             
          </fx:Declarations>
          <s:DropDownList x="109.35" y="141.05" id="dropDownList" prompt = "NL West" creationComplete="dropDownList_creationCompleteHandler(event)" labelField="division_champ" contentBackgroundColor="#F8F8F8" chromeColor="#F5F5F5" rollOverColor="#3035FF" selectionColor="#FF3C3C" focusColor="#9B9B9B" fontFamily="Georgia" dropShadowVisible="true" borderColor="#C8C8C8" requireSelection="true" >
              <s:AsyncListView list="{TypeUtility.convertToCollection(getTeamsByIDResult.lastResult)}"/>
          </s:DropDownList>
          <s:DropDownList x="109.3" y="252.55" id="dropDownList2" prompt = "NL East" creationComplete="dropDownList2_creationCompleteHandler(event)" labelField="division_champ" contentBackgroundColor="#F8F8F8" chromeColor="#F5F5F5" rollOverColor="#3035FF" selectionColor="#FF3C3C" focusColor="#9B9B9B" fontFamily="Georgia" dropShadowVisible="true" borderColor="#C8C8C8" requireSelection="true">
              <s:AsyncListView list="{TypeUtility.convertToCollection(getTeamsByIDResult2.lastResult)}"/>
          </s:DropDownList>
          <s:DropDownList x="108.85" y="335.9" id="dropDownList3" prompt = "NL Central" creationComplete="dropDownList3_creationCompleteHandler(event)" labelField="division_champ" contentBackgroundColor="#F8F8F8" chromeColor="#F5F5F5" rollOverColor="#3035FF" selectionColor="#FF3C3C" focusColor="#9B9B9B" fontFamily="Georgia" dropShadowVisible="true" borderColor="#C8C8C8" requireSelection="true">
              <s:AsyncListView list="{TypeUtility.convertToCollection(getTeamsByIDResult11.lastResult)}"/>
          </s:DropDownList>
          <s:DropDownList x="108.35" y="447.25" id="dropDownList4" prompt = "NL Wildcard" labelField="division_champ" creationComplete="dropDownList4_creationCompleteHandler(event)" contentBackgroundColor="#F8F8F8" chromeColor="#F5F5F5" rollOverColor="#3035FF" selectionColor="#FF3C3C" focusColor="#9B9B9B" fontFamily="Georgia" dropShadowVisible="true" borderColor="#C8C8C8" requireSelection="true">
              <s:AsyncListView list="{TypeUtility.convertToCollection(getTeamsByIDResult13.lastResult)}"/>
          </s:DropDownList>
          <s:DropDownList x="733.1" y="141.55" id="dropDownList5" prompt = "AL West" creationComplete="dropDownList5_creationCompleteHandler(event)" labelField="division_champ" selectionColor="#FF3C3C" rollOverColor="#3035FF" fontFamily="Georgia" dropShadowVisible="true" borderColor="#C8C8C8">
              <s:AsyncListView list="{TypeUtility.convertToCollection(getTeamsByIDResult12.lastResult)}"/>
          </s:DropDownList>
          <s:DropDownList x="733.05" y="253.05" id="dropDownList6" prompt = "AL East" creationComplete="dropDownList6_creationCompleteHandler(event)" labelField="division_champ" selectionColor="#FF3C3C" rollOverColor="#3035FF" fontFamily="Georgia" dropShadowVisible="true" borderColor="#C8C8C8">
              <s:AsyncListView list="{TypeUtility.convertToCollection(getTeamsByIDResult15.lastResult)}"/>
          </s:DropDownList>
          <s:DropDownList x="733.05" y="336.35" id="dropDownList7" prompt = "AL Central" creationComplete="dropDownList7_creationCompleteHandler(event)" labelField="division_champ" selectionColor="#FF3C3C" rollOverColor="#3035FF" fontFamily="Georgia" dropShadowVisible="true" borderColor="#C8C8C8">
              <s:AsyncListView list="{TypeUtility.convertToCollection(getTeamsByIDResult17.lastResult)}"/>
          </s:DropDownList>
          <s:DropDownList x="733.1" y="447.7" id="dropDownList8" prompt = "AL Wildcard" creationComplete="dropDownList8_creationCompleteHandler(event)" labelField="division_champ" selectionColor="#FF3C3C" rollOverColor="#3035FF" fontFamily="Georgia" dropShadowVisible="true" borderColor="#C8C8C8">
              <s:AsyncListView list="{TypeUtility.convertToCollection(getTeamsByIDResult18.lastResult)}"/>
          </s:DropDownList>
          <mx:HRule x="105.65" y="169.45" width="148"/>
          <mx:HRule x="105.3" y="280.95" width="148"/>
          <mx:VRule x="251.65" y="170.1" height="113"/>
          <mx:HRule x="105.65" y="364.45" width="148"/>
          <mx:HRule x="105.3" y="475.95" width="148"/>
          <mx:VRule x="251.65" y="365.1" height="113"/>
          <mx:HRule x="252.65" y="267.45" width="148"/>
          <mx:HRule x="399.1" y="296.2" width="121"/>
          <mx:HRule x="433.05" y="349.75" width="121"/>
          <mx:HRule x="252.3" y="378.95" width="148"/>
          <mx:VRule x="398.65" y="268.1" height="113"/>
          <mx:HRule x="701.55" y="169.35" width="148"/>
          <mx:HRule x="701.2" y="280.85" width="148"/>
          <mx:VRule x="700.55" y="170" height="113"/>
          <mx:HRule x="701.55" y="364.35" width="148"/>
          <mx:HRule x="701.2" y="475.85" width="148"/>
          <mx:VRule x="700.55" y="365" height="113"/>
          <mx:HRule x="553.15" y="267.4" width="148"/>
          <mx:HRule x="552.8" y="378.9" width="148"/>
          <mx:VRule x="552.15" y="268.05" height="113"/>
          <s:DropDownList x="276" y="238"  id="dropDownList9" prompt = "NLDS" creationComplete="dropDownList9_creationCompleteHandler(event)" labelField="division_champ" contentBackgroundColor="#F8F8F8" chromeColor="#F5F5F5" rollOverColor="#3035FF" selectionColor="#FF3C3C" focusColor="#9B9B9B" fontFamily="Georgia" dropShadowVisible="true" borderColor="#C8C8C8">
              <s:AsyncListView list="{TypeUtility.convertToCollection(getTeamsByDivIDResult.lastResult)}"/>
          </s:DropDownList>
          <s:Label x="117.75" y="60.95" text="NLDS" fontSize="21" fontFamily="Georgia" width="84" height="31" color="#FFFFFF"/>
          <s:Label x="291.5" y="61" text="NLCS" fontSize="21" fontFamily="Georgia" width="84" height="31" color="#FFFFFF"/>
          <s:DropDownList x="275" y="349" id="dropDownList10" prompt = "NLDS" creationComplete="dropDownList10_creationCompleteHandler(event)" labelField="division_champ" contentBackgroundColor="#F8F8F8" chromeColor="#F5F5F5" rollOverColor="#3035FF" selectionColor="#FF3C3C" focusColor="#9B9B9B" fontFamily="Georgia" dropShadowVisible="true" borderColor="#C8C8C8">
              <s:AsyncListView list="{TypeUtility.convertToCollection(getTeamsByDivIDResult2.lastResult)}"/>       
          </s:DropDownList>
          <s:DropDownList x="566" y="238" id="dropDownList12" prompt = "ALDS" creationComplete="dropDownList12_creationCompleteHandler(event)" labelField="division_champ" selectionColor="#FF3C3C" rollOverColor="#3035FF" fontFamily="Georgia" dropShadowVisible="true" borderColor="#C8C8C8">
              <s:AsyncListView list="{getTeamsByDivIDResult4.lastResult}"/></s:DropDownList>
          <s:DropDownList x="566" y="349" id="dropDownList13" prompt = "ALDS" creationComplete="dropDownList13_creationCompleteHandler(event)" labelField="division_champ" selectionColor="#FF3C3C" rollOverColor="#3035FF" fontFamily="Georgia" dropShadowVisible="true" borderColor="#C8C8C8">
              <s:AsyncListView list="{getTeamsByDivIDResult5.lastResult}"/></s:DropDownList>
          <s:DropDownList x="408" y="267" id="dropDownList11" prompt = "NLCS" creationComplete="dropDownList11_creationCompleteHandler(event)" labelField="division_champ" chromeColor="#F5F5F5" selectionColor="#FF3C3C" rollOverColor="#3035FF" focusColor="#9B9B9B" fontFamily="Georgia" dropShadowVisible="true" borderColor="#C8C8C8">
              <s:AsyncListView list="{TypeUtility.convertToCollection(getTeamsByLeagueIDResult.lastResult)}"/>
          </s:DropDownList>
          <s:DropDownList x="433" y="360" id="dropDownList14" prompt = "ALCS" creationComplete="dropDownList14_creationCompleteHandler(event)" labelField="division_champ" selectionColor="#FF3C3C" rollOverColor="#3035FF" fontFamily="Georgia" dropShadowVisible="true" borderColor="#C8C8C8">
              <s:AsyncListView list="{TypeUtility.convertToCollection(getTeamsByLeagueIDResult2.lastResult)}"/>
          </s:DropDownList>
          <s:Label x="117.75" y="60.95" text="NLDS" fontSize="21" fontFamily="Georgia" width="84" height="31" color="#FFFFFF"/>
          <s:Label x="612.35" y="61.45" text="ALCS" fontSize="21" fontFamily="Georgia" width="84" height="31" color="#FFFFFF"/>
          <s:Label x="786.1" y="61.5" text="ALDS" fontSize="21" fontFamily="Georgia" width="84" height="31" color="#FFFFFF"/>
          <s:Label x="291.5" y="61" text="NLCS" fontSize="21" fontFamily="Georgia" width="84" height="31" color="#FFFFFF"/>
          <s:Label x="13" y="150" text="{getTeamsByIDResult3.lastResult.division}" color="#FFFFFF" id="label2" creationComplete="label2_creationCompleteHandler(event)"/>
          <s:Label x="13" y="260.95" text="{getTeamsByIDResult4.lastResult.division}" color="#FFFFFF" id="label3" creationComplete="label3_creationCompleteHandler(event)"/>
          <s:Label x="13" y="344.8" text="{getTeamsByIDResult5.lastResult.division}" color="#FFFFFF" id="label4" creationComplete="label4_creationCompleteHandler(event)"/>
          <s:Label x="13" y="456.75" text="{getTeamsByIDResult6.lastResult.division}" color="#FFFFFF" id="label5" creationComplete="label5_creationCompleteHandler(event)"/>
          <s:Label x="865.8" y="150" text="{getTeamsByIDResult7.lastResult.division}" color="#FFFFFF" id="label6" creationComplete="label6_creationCompleteHandler(event)" textAlign="right"/>
          <s:Label x="865.8" y="260.95" text="{getTeamsByIDResult8.lastResult.division}" color="#FFFFFF" id="label7" creationComplete="label7_creationCompleteHandler(event)" textAlign="right"/>
          <s:Label x="865.8" y="344.8" text="{getTeamsByIDResult9.lastResult.division}" color="#FFFFFF" id="label8" creationComplete="label8_creationCompleteHandler(event)" textAlign="right"/>
          <s:Label x="865.8" y="456.75" text="{getTeamsByIDResult10.lastResult.division}" color="#FFFFFF" id="label9" creationComplete="label9_creationCompleteHandler(event)" textAlign="right"/>
          <s:DropDownList x="421" y="314" id="dropDownList15" prompt = "World Series" creationComplete="dropDownList15_creationCompleteHandler(event)" labelField="division_champ" selectionColor="#FF3C3C" rollOverColor="#3035FF" fontFamily="Georgia" dropShadowVisible="true" borderColor="#C8C8C8">
              <s:AsyncListView list="{getAllTeamsResult4.lastResult}"/>
          </s:DropDownList>
          <s:Label x="371.85" y="127.7" text="2010 World Series" width="187" height="76" fontSize="23" color="#D1D1D1" fontFamily="Verdana" verticalAlign="top" textAlign="center" fontWeight="bold"/>
          <s:Panel x="382" y="420" width="181" height="145" title=" Submit Your Bracket" color="#4229FF" fontSize="13" textAlign="left" fontFamily="Verdana">
              <s:TextInput x="51.85" y="10" width="121" height="24" id="newUserTxt" contentBackgroundColor="#4B4BFF" color="#FFFFFF" borderVisible="true" borderAlpha="1.0"/>
              <s:TextInput x="51.85" y="44" width="121" height="24" id="newEmailTxt" contentBackgroundColor="#4B4BFF" color="#FFFFFF" borderVisible="true" borderAlpha="1.0"/>
              <s:Label x="4" y="17" text="NAME" fontFamily="Arial" fontWeight="bold" color="#000000" fontSize="16"/>
              <s:Label x="2" y="53" text="EMAIL" fontFamily="Arial" fontWeight="bold" color="#000000" fontSize="16"/>
              <s:Button x="54" y="77" label="Submit" click="addNewUser() ; "/>
          </s:Panel>
      </s:Application>