Link to home
Start Free TrialLog in
Avatar of AuthorwareXtras
AuthorwareXtras

asked on

Show result of an HTTPService call to PHP script in Alert

I have a simple PHP script to show the number fo records in a table:

$sql = "SELECT COUNT(*) FROM delegates";
      $res = mysql_query($sql);
       if (!$res) {
          die('Invalid query: ' . mysql_error());
      }
      $row = mysql_fetch_array($res, MYSQL_NUM);
      echo $row[0];

If I point the browser to this, it returns the correct number of records.

I now want to use Flex 3 to call this page as an HTTPService.

I am setting it up like this:
<mx:HTTPService id="checkNumbers" resultFormat="text" url="http://path/to/file/getnumbersreg.php"/>

and in the application creation complete handler calling:
checkNumbers.send();
Alert.show(String(checkNumbers.lastResult));

The alert box always shows a result of 'Null'.

Can someone help out with this.  I need to be able to take the number that is returned and work it in a different section of the application.

Thanks



Avatar of julianopolito
julianopolito
Flag of Brazil image

You should use a handler in this case, because by the moment you call the Alert.show, lastResult hasnt received a result yet.

<mx:HTTPService id="checkNumbers" resultFormat="text" result="rhandler(e:ResultEvent)" url="http://path/to/file/getnumbersreg.php"/>


then

private function rhandler(e:ResultEvent):void{
     Alert.show(e.result);
}
Avatar of AuthorwareXtras
AuthorwareXtras

ASKER

That won't even compile!  It must be late.....

1084: Syntax error: expecting rightparen before colon.

on this line
<mx:HTTPService id="checkNumbers" resultFormat="text" result="rhandler(e:ResultEvent)" url="http://path/tophp/file//getnumbersreg.php"/>
      
That's very unlikely. Here it compiles fine. There must be something else. Can you recheck the actual code to see if there is nothing missing? Can you post complete code so I can check that for you?
OK, but there is quite a bit....
<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" creationComplete="handleCreationComplete()" layout="absolute" backgroundColor="#FFFFFF" width="488" height="487">
  
  <mx:HTTPService id="srv" url="https://path/to/addform.php" showBusyCursor="true" method="POST">
    <mx:request>
      <firstname>{firstname.text}</firstname>
      <lastname>{lastname.text}</lastname>
      <company>{company.text}</company>
      <email>{email.text}</email>
      <address>{address.text}</address>
      <city>{city.text}</city>
      <state>{state.text}</state>
      <postcode>{postcode.text}</postcode>
      <country>{country.text}</country>
      <phone>{phone.text}</phone>
      <fax>{fax.text}</fax>
      <noofdelegates>{cmbDelegates.text}</noofdelegates>
      <roomsday1>{cmbRoomMonday.text}</roomsday1>
      <roomsday2>{cmbRoomTuesday.text}</roomsday2>
      <roomsday3>{cmbRoomWednesday.text}</roomsday3>
      <cctype>{cmbcctype.text}</cctype>
      <ccnumber>{ccnumber.text}</ccnumber>
      <expdate>{expdate.text}</expdate>
      <ccv>{ccv.text}</ccv>
      <ccname>{ccname.text}</ccname>
    </mx:request>
  </mx:HTTPService>
<mx:HTTPService id="checkNumbers" resultFormat="text" result="resultHandler(e:ResultEvent)" url="https://path/to/getnumbersreg.php"/>
 
<mx:Script>
<![CDATA[
 
	import mx.controls.Alert;
	import mx.rpc.events.ResultEvent;
	
private function onNext():void{ 
if (vsPage.selectedIndex+1 < vsPage.numChildren){
	vsPage.selectedIndex ++;
	}
}
 
private function onBack():void{ 
 
if (vsPage.selectedIndex > 0){
 
	vsPage.selectedIndex --;
	}
}
 
private function handleCreationComplete():void{
	checkNumbers.send();
}
 
private function resultHandler(e:ResultEvent):void{
     Alert.show(e.result);
}
 
private function onChange(blnDelegatesChanged:Boolean):void{
 
//calculate delegates
lblUnit.text =String(cmbDelegates.selectedIndex * 500);
lblVAT.text = String(17.5/100*Number(lblUnit.text));
lblTotal.text = String(Number(lblUnit.text)+Number(lblVAT.text));
 
 
//If they changed the number of delegates, we pre fill the number of rooms accordingly
if (blnDelegatesChanged){
	cmbRoomMonday.selectedIndex = cmbDelegates.selectedIndex;
	cmbRoomTuesday.selectedIndex = cmbDelegates.selectedIndex;
	cmbRoomWednesday.selectedIndex = cmbDelegates.selectedIndex;
}
//Rooms for first night
lblRoom1Unit.text = String(cmbRoomMonday.selectedIndex * 59.57);
lblRoom1VAT.text = String(17.5/100*Number(lblRoom1Unit.text));
lblRoom1Total.text = String(Number(lblRoom1Unit.text)+Number(lblRoom1VAT.text));
 
 
 
//Rooms for Second Night
lblRoom2Unit.text = String(cmbRoomTuesday.selectedIndex * 59.57);
lblRoom2VAT.text = String(17.5/100*Number(lblRoom2Unit.text));
lblRoom2Total.text = String(Number(lblRoom2Unit.text)+Number(lblRoom2VAT.text));
 
 
//Rooms for Third Night
lblRoom3Unit.text = String(cmbRoomWednesday.selectedIndex * 59.57);
lblRoom3VAT.text = String(17.5/100*Number(lblRoom3Unit.text));
lblRoom3Total.text = String(Number(lblRoom3Unit.text)+Number(lblRoom3VAT.text));
 
 
//total calcs
lblTotalUnit.text = String(Number(lblUnit.text)+Number(lblRoom1Unit.text)+Number(lblRoom2Unit.text)+Number(lblRoom3Unit.text));
lblVATTotal.text = String(Number(lblVAT.text)+Number(lblRoom1VAT.text)+Number(lblRoom2VAT.text)+Number(lblRoom3VAT.text));
lblGrandTotal.text = String(Number(lblTotal.text)+Number(lblRoom1Total.text)+Number(lblRoom2Total.text)+Number(lblRoom3Total.text));
 
//formatting delegates
lblUnit.text= gbpFormatter.format(lblUnit.text);
lblVAT.text= gbpFormatter.format(lblVAT.text);
lblTotal.text= gbpFormatter.format(lblTotal.text);
//formatting Rooms 1
lblRoom1Unit.text = gbpFormatter.format(lblRoom1Unit.text);
lblRoom1VAT.text = gbpFormatter.format(lblRoom1VAT.text);
lblRoom1Total.text = gbpFormatter.format(lblRoom1Total.text);
//formatting Rooms 2
lblRoom2Unit.text = gbpFormatter.format(lblRoom2Unit.text);
lblRoom2VAT.text = gbpFormatter.format(lblRoom2VAT.text);
lblRoom2Total.text = gbpFormatter.format(lblRoom2Total.text);
//formatting Rooms 3
lblRoom3Unit.text = gbpFormatter.format(lblRoom3Unit.text);
lblRoom3VAT.text = gbpFormatter.format(lblRoom3VAT.text);
lblRoom3Total.text = gbpFormatter.format(lblRoom3Total.text);
//formatting totals
lblTotalUnit.text = gbpFormatter.format(lblTotalUnit.text);
lblVATTotal.text = gbpFormatter.format(lblVATTotal.text);
lblGrandTotal.text = gbpFormatter.format(lblGrandTotal.text);
}
]]>
</mx:Script>
 
 
<mx:CurrencyFormatter id="gbpFormatter" precision="2" 
currencySymbol="£" decimalSeparatorFrom="."
decimalSeparatorTo="." useNegativeSign="true" 
useThousandsSeparator="false" alignSymbol="left"/>
 
 
<mx:Button label="Next" x="425" y="455" click="onNext()" enabled="{vsPage.selectedIndex!=2}" visible="{vsPage.selectedIndex!=2}"/>
<mx:Button label="Back" x="10" y="455" click="onBack()" enabled="{vsPage.selectedIndex > 0}"/>
<mx:Button label="Send" x="425" y="455" click="srv.send()"  visible="{vsPage.selectedIndex==2}"/>
 
<mx:ViewStack y="10" height="437" id="vsPage" x="10">
 
<mx:Panel x="10" y="10" width="470" height="467" layout="absolute" title="Customer Details ">
	<mx:Form x="1" y="10" width="449" height="377" id="frmCustomer">
	<mx:FormItem label="First Name:" horizontalAlign="left" width="100%">
		<mx:TextInput id="firstname" width="100%"/>
	</mx:FormItem>
 
 
	<mx:FormItem label="Last Name:" horizontalAlign="left" width="100%">
		<mx:TextInput id="lastname" width="100%"/>
	</mx:FormItem>
 
 
	<mx:FormItem label="Company:" horizontalAlign="left" width="100%">
		<mx:TextInput id="company" width="100%"/>
	</mx:FormItem>
 
 
	<mx:FormItem label="Your E-mail:" width="100%"><mx:TextInput id="email" width="100%"/></mx:FormItem>
 
 
<mx:FormItem label="Confirm E-mail:" width="100%"><mx:TextInput id="confirmEmail" width="100%"/></mx:FormItem>
 
<mx:FormItem label="Geographical Address:" width="100%"><mx:TextInput id="address" width="100%"/></mx:FormItem>
 
<mx:FormItem label="City / Town:" width="100%"><mx:TextInput id="city" width="100%"/></mx:FormItem>
 
<mx:FormItem label="County/State/Province:" width="100%"><mx:TextInput id="state" width="100%"/></mx:FormItem>
 
<mx:FormItem label="Zip / Postal:" width="100%"><mx:TextInput id="postcode" width="100%"/></mx:FormItem>
 
<mx:FormItem label="Country" width="100%"><mx:TextInput id="country" width="100%"/></mx:FormItem>
 
<mx:FormItem label="Telephone" width="100%"><mx:TextInput id="phone" width="100%"/></mx:FormItem>
 
<mx:FormItem label="Fax" width="100%"><mx:TextInput id="fax" width="100%"/></mx:FormItem>
 
</mx:Form>
 
</mx:Panel>
 
 
<mx:Panel x="10" y="10" width="470" height="467" layout="absolute" title="Order Details">
 
<mx:Form x="0" y="10" width="358" height="367" id="frmOrder">
 
<mx:Label text="Summit Delegates" width="151" fontWeight="bold"/>
<mx:FormItem width="100%" height="50">
 
<mx:ComboBox width="53" id="cmbDelegates" change="onChange(true)">
<mx:ArrayCollection>
	<mx:String>0</mx:String>
	<mx:String>1</mx:String>
	<mx:String>2</mx:String>
	<mx:String>3</mx:String>
	<mx:String>4</mx:String>
	<mx:String>5</mx:String>
	<mx:String>6</mx:String>
	<mx:String>7</mx:String>
	<mx:String>8</mx:String>
	<mx:String>9</mx:String>
</mx:ArrayCollection>
 
</mx:ComboBox>
 
</mx:FormItem>
<mx:Label text="Single Room Accommodation in Halls of Residence" fontWeight="bold" width="302"/>
<mx:FormItem width="100%">
	<mx:ComboBox width="53" id="cmbRoomMonday" change="onChange(false)">
	<mx:ArrayCollection>
		<mx:String>0</mx:String>
		<mx:String>1</mx:String>
		<mx:String>2</mx:String>
		<mx:String>3</mx:String>
		<mx:String>4</mx:String>
		<mx:String>5</mx:String>
		<mx:String>6</mx:String>
		<mx:String>7</mx:String>
		<mx:String>8</mx:String>
		<mx:String>9</mx:String>
	</mx:ArrayCollection>
</mx:ComboBox>
	</mx:FormItem>
 
	<mx:FormItem width="100%">
		<mx:ComboBox width="53" id="cmbRoomTuesday" change="onChange(false)">
<mx:ArrayCollection>
	<mx:String>0</mx:String>
	<mx:String>1</mx:String>
	<mx:String>2</mx:String>
	<mx:String>3</mx:String>
	<mx:String>4</mx:String>
	<mx:String>5</mx:String>
	<mx:String>6</mx:String>
	<mx:String>7</mx:String>
	<mx:String>8</mx:String>
	<mx:String>9</mx:String>
</mx:ArrayCollection>
</mx:ComboBox>
	</mx:FormItem>
	<mx:FormItem width="100%" height="71">
		<mx:ComboBox width="53" id="cmbRoomWednesday" change="onChange(false)">
<mx:ArrayCollection>
	<mx:String>0</mx:String>
	<mx:String>1</mx:String>
	<mx:String>2</mx:String>
	<mx:String>3</mx:String>
	<mx:String>4</mx:String>
	<mx:String>5</mx:String>
	<mx:String>6</mx:String>
	<mx:String>7</mx:String>
	<mx:String>8</mx:String>
	<mx:String>9</mx:String>
</mx:ArrayCollection>
</mx:ComboBox>
	</mx:FormItem>
<mx:Label text="Total Costs" width="138" fontWeight="bold"/>
</mx:Form>
 
<mx:Label x="97" y="54" text="Summit Delegate(s)" width="123"/>
 
<mx:Label x="376" y="54" width="62" id="lblTotal" text="£0.00"/>
 
<mx:Label x="244" y="10" text="Unit" fontWeight="bold"/>
 
<mx:Label x="312" y="10" text="VAT" fontWeight="bold"/>
 
<mx:Label x="376" y="10" text="Total" fontWeight="bold"/>
 
<mx:Label x="236" y="54" width="58" id="lblUnit" text="£0.00"/>
 
<mx:Label x="304" y="54" width="54" id="lblVAT" text="£0.00"/>
	<mx:Label x="96" y="134" text="Rooms 18th Aug 2008" width="133"/>
	<mx:Label x="96" y="161" text="Rooms 19th Aug 2008" width="130"/>
	<mx:Label text="Rooms 20th Aug 2008" x="97" y="189"/>
	<mx:Label x="237" y="134" text="£0.00" id="lblRoom1Unit" width="59"/>
	<mx:Label x="237" y="161" text="£0.00" id="lblRoom2Unit" width="59"/>
	<mx:Label x="237" y="189" text="£0.00" id="lblRoom3Unit" width="59"/>
	<mx:Label x="304" y="134" text="£0.00" id="lblRoom1VAT" width="54"/>
	<mx:Label x="304" y="161" text="£0.00" id="lblRoom2VAT" width="54"/>
	<mx:Label x="304" y="189" text="£0.00" id="lblRoom3VAT" width="54"/>
	<mx:Label x="376" y="134" text="£0.00" id="lblRoom1Total" width="64"/>
	<mx:Label x="376" y="161" text="£0.00" id="lblRoom2Total" width="64"/>
	<mx:Label x="376" y="189" text="£0.00" width="64" id="lblRoom3Total"/>
	<mx:Label x="237" y="266" text="£0.00" id="lblTotalUnit" width="60" fontWeight="bold"/>
	<mx:Label x="305" y="266" text="£0.00" id="lblVATTotal" width="63" fontWeight="bold"/>
	<mx:Label x="376" y="266" text="£0.00" id="lblGrandTotal" width="64" fontWeight="bold"/>
 
</mx:Panel> 
 
<mx:Panel title="Credit Card Details">
<mx:Form x="0" y="10" width="421" height="384" id="frmCreditCard">
<mx:FormItem label="Credit Card Number" width="100%"><mx:TextInput id="ccnumber" width="100%"/></mx:FormItem>
<mx:FormItem width="100%" label="Credit Card Type"><mx:ComboBox width="100%" id="cmbcctype">
<mx:ArrayCollection>
	<mx:String>Visa</mx:String>
	<mx:String>Mastercard</mx:String>
	</mx:ArrayCollection>
</mx:ComboBox></mx:FormItem>
<mx:FormItem label="Name On Card" width="100%"><mx:TextInput id="ccname" width="100%"/></mx:FormItem>
<mx:FormItem label="Card Security Code (CVV)" width="100%"><mx:TextInput id="ccv" width="100%"/></mx:FormItem>
<mx:FormItem label="Expiry Date" width="100%"><mx:TextInput id="expdate" width="100%"/></mx:FormItem>
 
</mx:Form>
</mx:Panel>
</mx:ViewStack>
 
</mx:Application>

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of julianopolito
julianopolito
Flag of Brazil image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial