PDA

View Full Version : php, mysql, flex 2 datagrid population


colorada
08-11-2007, 05:10 PM
Hello I have gone through my code for about a 5 hours now and am still not getting it to work. Basically what I am trying to do is populate a datagrid that is populated from field when submitted.

I got the tutorial from http://www.adobe.com/devnet/flex/articles/flex2_php_print.html

And when I just use the default in the tutorial it works great.

I obviously want to modify it and use it for my project. Can anyone please take a look at this code and tell me what it is I am missing please?

//PHP

<?php
define( "DATABASE_SERVER", "localhost" );
define( "DATABASE_USERNAME", "root" );
define( "DATABASE_PASSWORD", "" );
define( "DATABASE_NAME", "tech" );

//connect to the database
$mysql = mysql_connect(DATABASE_SERVER, DATABASE_USERNAME, DATABASE_PASSWORD);

mysql_select_db( DATABASE_NAME );

// Quote variable to make safe
function quote_smart($value)
{
// Stripslashes
if (get_magic_quotes_gpc()) {
$value = stripslashes($value);
}
// Quote if not integer
if (!is_numeric($value)) {
$value = "'" . mysql_real_escape_string($value) . "'";
}
return $value;
}

if( $_POST["tech_name"] AND $_POST["site_id"] AND $_POST["site_name"] AND $_POST["date"] AND $_POST["trouble_ticket"] AND $_POST["vend_assi"] AND $_POST["resolution"] AND $_POST["comments"])
{
//add the user
$Query = sprintf("INSERT INTO site_info VALUES ('', %s, %s, %s, %s, %s, %s, %s, %s)", quote_smart($_POST['tech_name']), quote_smart($_POST['site_id']), quote_smart($_POST['site_name']), quote_smart($_POST['date']), quote_smart($_POST['trouble_ticket']), quote_smart($_POST['vend_assi']), quote_smart($_POST['resolution']), quote_smart($_POST['comments']));

$Result = mysql_query( $Query );
}

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

$Return = "<site_info>";

while ( $Data = mysql_fetch_object( $Result ) )
{
$Return .= "<info>
<theid>".$User->the_id."</theid><technician>".$Data->tech_name."</technician><siteid>".$Data->site_id."</siteid><sitename>".$Data->site_name."</sitename><date>".$Data->date."</date><troubleticket>".$Data->trouble_ticket."</troubleticket><vendassi>".$Data->vend_assi."</vendassi><resolution>".$Data->resolution."</resolution><comments>".$Data->comments."</comments>
</info>";


}
$Return .= "</site_info>";
mysql_free_result( $Result );
print ($Return)
?>



//MXML Flex 2

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

<!--THIS IS THE REQUEST TO THE PHP FILE THAT CONNECTS TO THE DATABASE AND POST/REQUEST DATA-->
<mx:HTTPService id="userRequest" url="http://localhost/tmojaxreporting/private/request.php" useProxy="false" method="POST">
<mx:request xmlns="">
<technician>{tech_name.text}</technician>
<siteid>{site_id.text}</siteid>
<sitename>{site_name.text}</sitename>
<date>{date.text}</date>
<troubleticket>{trouble_ticket.text}</troubleticket>
<vendassi>{vend_assi.text}</vendassi>
<resolution>{resolution.text}</resolution>
<comments>{comments.text}</comments>
</mx:request>
</mx:HTTPService>


<!--THIS IS THE INPUT FIELDS TO POST THE DATA TO THE DATA GRID-->
<mx:Form x="22" y="10" width="493">
<mx:HBox>
<mx:Label text="Technician"/>
<mx:TextInput id="tech_name"/>
</mx:HBox>
<mx:HBox>
<mx:Label text="Site ID"/>
<mx:TextInput id="site_id"/>
</mx:HBox>
<mx:HBox>
<mx:Label text="Site Name"/>
<mx:TextInput id="site_name"/>
</mx:HBox>
<mx:HBox>
<mx:Label text="Date"/>
<mx:TextInput id="date"/>
</mx:HBox>
<mx:HBox>
<mx:Label text="Trouble Ticket"/>
<mx:TextInput id="trouble_ticket"/>
</mx:HBox>
<mx:HBox>
<mx:Label text="Vendor"/>
<mx:TextInput id="vend_assi"/>
</mx:HBox>
<mx:HBox>
<mx:Label text="Resolution"/>
<mx:TextInput id="resolution"/>
</mx:HBox>
<mx:HBox>
<mx:Label text="Comments"/>
<mx:TextInput id="comments"/>
</mx:HBox>
</mx:Form>

<!--THIS IS THE DATA GRID-->
<mx:DataGrid id="dgUserRequest" x="22" y="313" dataProvider="{userRequest.lastResult.site_info.info}">
<mx:columns>
<!-- <mx:DataGridColumn headerText="ID" dataField="ID"/>-->
<mx:DataGridColumn headerText="Technician" dataField="tech_name"/>
<mx:DataGridColumn headerText="Site ID" dataField="site_id"/>
<mx:DataGridColumn headerText="Site Name" dataField="site_name"/>
<mx:DataGridColumn headerText="Date" dataField="date"/>
<mx:DataGridColumn headerText="Trouble Ticket" dataField="trouble_ticket"/>
<mx:DataGridColumn headerText="Vendor" dataField="vend_assi"/>
<mx:DataGridColumn headerText="Resolution" dataField="resolution"/>
<mx:DataGridColumn headerText="Comments" dataField="comments"/>
</mx:columns>
</mx:DataGrid>

<!--THIS IS THE TEXT BOX FOR RESOLUTION DISPLAY-->
<mx:TextInput x="22" y="478" id="selectedResolution" text="{dgUserRequest.selectedItem.resolution}"/>

<!--THIS SUBMIT BUTTON TO POST AND REQUEST DATA-->
<mx:Button label="Submit" click="userRequest.send()" x="22" y="268"/>
</mx:Application>


//SQL/MySQl Database

CREATE TABLE `site_info` (
`the_id` int(11) NOT NULL auto_increment,
`tech_name` varchar(40) NOT NULL,
`site_id` varchar(40) NOT NULL,
`site_name` varchar(40) NOT NULL,
`date` varchar(40) NOT NULL,
`trouble_ticket` varchar(40) NOT NULL,
`vend_assi` varchar(40) NOT NULL,
`resolution` varchar(255) default NULL,
`comments` varchar(255) default NULL,
PRIMARY KEY (`the_id`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=5 ;


I am sure it is something simple but I cannot figure it our for the life of me.

Thanks,

colorada

colorada
08-11-2007, 09:45 PM
Ok I was finally able to get the data from the database to the grid but I still cannot get it to write to it from my form.

Here is the updated Code from Flex 2. PHP and the SQL did not change.

//MXML

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

<!--THIS IS THE REQUEST TO THE PHP FILE THAT CONNECTS TO THE DATABASE AND POST/REQUEST DATA-->
<mx:HTTPService id="userRequest" url="http://localhost/tmojaxreporting/private/request.php" useProxy="false" method="POST">
<mx:request xmlns="">
<technician>{tech_name.text}</technician>
<siteid>{site_id.text}</siteid>
<sitename>{site_name.text}</sitename>
<date>{date.text}</date>
<troubleticket>{trouble_ticket.text}</troubleticket>
<vendassi>{vend_assi.text}</vendassi>
<resolution>{resolution.text}</resolution>
<comments>{comments.text}</comments>
</mx:request>
</mx:HTTPService>


<!--THIS IS THE INPUT FIELDS TO POST THE DATA TO THE DATA GRID-->
<mx:Form x="22" y="10" width="493">
<mx:HBox>
<mx:Label text="Technician"/>
<mx:TextInput id="tech_name"/>
</mx:HBox>
<mx:HBox>
<mx:Label text="Site ID"/>
<mx:TextInput id="site_id"/>
</mx:HBox>
<mx:HBox>
<mx:Label text="Site Name"/>
<mx:TextInput id="site_name"/>
</mx:HBox>
<mx:HBox>
<mx:Label text="Date"/>
<mx:TextInput id="date"/>
</mx:HBox>
<mx:HBox>
<mx:Label text="Trouble Ticket"/>
<mx:TextInput id="trouble_ticket"/>
</mx:HBox>
<mx:HBox>
<mx:Label text="Vendor"/>
<mx:TextInput id="vend_assi"/>
</mx:HBox>
<mx:HBox>
<mx:Label text="Resolution"/>
<mx:TextInput id="resolution"/>
</mx:HBox>
<mx:HBox>
<mx:Label text="Comments"/>
<mx:TextInput id="comments"/>
</mx:HBox>
</mx:Form>

<!--THIS IS THE DATA GRID-->
<mx:DataGrid id="dgUserRequest" x="22" y="313" dataProvider="{userRequest.lastResult.site_info.info}">
<mx:columns>
<mx:DataGridColumn headerText="ID" dataField="theid"/>
<mx:DataGridColumn headerText="Technician" dataField="technician"/>
<mx:DataGridColumn headerText="Site ID" dataField="siteid"/>
<mx:DataGridColumn headerText="Site Name" dataField="sitename"/>
<mx:DataGridColumn headerText="Date" dataField="date"/>
<mx:DataGridColumn headerText="Trouble Ticket" dataField="troubleticket"/>
<mx:DataGridColumn headerText="Vendor" dataField="vendassi"/>
<mx:DataGridColumn headerText="Resolution" dataField="resolution"/>
<mx:DataGridColumn headerText="Comments" dataField="comments"/>
</mx:columns>
</mx:DataGrid>

<!--THIS IS THE TEXT BOX FOR RESOLUTION DISPLAY-->
<mx:TextInput x="22" y="478" id="selectedResolution" text="{dgUserRequest.selectedItem.resolution}"/>

<!--THIS SUBMIT BUTTON TO POST AND REQUEST DATA-->
<mx:Button label="Submit" click="userRequest.send()" x="22" y="268"/>
</mx:Application>


The Bold Text is what was changed.

Thanks for anyone looking at this I am still working as well just need a few set of eyes.

colorada
08-11-2007, 09:54 PM
ok found what I was doing wrong and I learned so much debugging it.

Thank you all for helping me through this...lol


it was in my php and flex refer to the change above post for flex here was the php fix


if( $_POST["technician"] AND $_POST["siteid"] AND $_POST["sitename"] AND $_POST["date"] AND $_POST["troubleticket"] AND $_POST["vendassi"] AND $_POST["resolution"] AND $_POST["comments"])
{
//add the user
$Query = sprintf("INSERT INTO site_info VALUES ('', %s, %s, %s, %s, %s, %s, %s, %s)", quote_smart($_POST['technician']), quote_smart($_POST['siteid']), quote_smart($_POST['sitename']), quote_smart($_POST['date']), quote_smart($_POST['troubleticket']), quote_smart($_POST['vendassi']), quote_smart($_POST['resolution']), quote_smart($_POST['comments']));

$Result = mysql_query( $Query );
}



I was confused on where the data was being pulled.