TheMightySpud
03-12-2008, 11:09 AM
Hi all,
I'm currently working on a university project to create a small Flash Application for use on a PDA which needs to use PHP and a Database.
Due to security reasons, the University won't let me use a MySQL database, and have insisted on an Access DB, which in itself is a pain, but that's not the problem.
Also, I'm limited to using ActionScript 2.0 again, due to University resources.
My idea is to create a registration system for a school. The plan is as follows.
Upon loading the app, the user (a teacher) is shown a login page.
Login Screen (http://www.st-t.co.uk/nt/screen001.jpg)
Once a username and password are entered, the app then takes you to a registration screen.
Registration Screen (http://www.st-t.co.uk/nt/screen002.jpg)
Which displays all of the School Students that are linked to the class that the teacher is responsible for and displays a dropdown box with a number of options (absent, present, holiday) which will need to be selected on a daily basis (at the start of the day) and the results put into the database. Also on this page there is a 'More' button, which when clicked will take the user to a details page.
Details Screen (http://www.st-t.co.uk/nt/screen003.jpg)
The details page will display all the important information pertaining to the student that has been selected.
I've attached all of the files I have so far to this post, to make it easier for everyone :)
Now, my problem is thus, well, it's more like two problems really.
Firstly, I'm not 100% sure I'm tackling this the correct way, so if anyone knows of a better way to do what I want to do, I would be most grateful of any input. :)
Secondly, the way that I'm dealing with it at the moment is having variables from the login form being passed to the PHP script which performs the query and outputs the results to XML which is then sent back to the Flash app for displaying.
The problem is, that the XML doesn't get passed back to the Flash, and it's beginning to really annoy me, I've been searching around for nearly four weeks, but with no success, and with the deadline for the work only another four weeks away, I need to get it sorted ASAP.
So, onto the Code.
AS2.0 Code. Frame 1 - Stage Elements = Two Input Text boxes and 1 Button
//create varObject for sendingData
var lvoutput:LoadVars = new LoadVars();
lvoutput.Username = txtUsername.text;
lvoutput.Password = txtPassword.text;
//create xmlObject for returnData
var returnedData:XML = new XML();
returnedData.ignoreWhite = true;
returnedData.onLoad = function(success){
if (!success) {
trace("failed to load/find php script");
}else{
//check for error XML or valid XML
trace("PHP Script found");
//parse XML data
trace("Returned XML: "+ newline + returnedData + newline);
}
}
//make call to php script
LoginButton.onPress = function() {
lvoutput.sendAndLoad("ReadDB3.php", returnedData, "POST");
gotoAndPlay(5);
}
stop();
AS2.0 Code. Frame 5 - Stage Elements = One Listboc for displaying the returned data
onEnterFrame = function() {
ListOutput.htmlText = returnedData;
}
stop();
And the PHP (Works fine when sending username & password from HTML Form and outputs correct XML) :
<?php
//=====================================//
// gets data from form, may be an empty string
$sUsername = $_POST["Username"];
$sPassword = $_POST["Password"];
//=====================================//
// Database Section
//=====================================//
// creates a new Common-Object-Model (COM) connection object
$adoCon = new COM("ADODB.Connection");
// the path to the folder holding this PHP script
$sHere = dirname(__FILE__);
// opens the connection using a standard Access connection string
$adoCon->Open("Provider=Microsoft.Jet.OLEDB.4.0; Data Source=$sHere/Registerdbs.mdb");
$sSQL= "SELECT * FROM tblPupilInfo WHERE class LIKE
(SELECT currentclass FROM tblStaffLogin WHERE Username LIKE '$sUsername' and Password LIKE '$sPassword')";
// searches the DB
$rsMain = $adoCon->Execute( $sSQL );
//=====================================//
// Begins Creating XML Formated Code
echo "<?xml version=\"1.0\"?>\n";
echo "<pupilinfo>\n";
//=====================================//
// Assigns Query results to variable for use later
while (!$rsMain->EOF)
{ // gets each of the fields
$sPupilID = $rsMain->Fields("ID")->value;
$sPupilSurname = $rsMain->Fields("Surname")->value;
$sPupilForename = $rsMain->Fields("Forename")->value;
$sPupilDOB = $rsMain->Fields("DOB")->value;
$sPupilAddress = $rsMain->Fields("Address")->value;
$sPupilEmergency = $rsMain->Fields("Emergency Contact")->value;
$sPupilClass = $rsMain->Fields("Class")->value;
//=====================================//
// Continues Creating XML Formated Code
echo "<pupil>\n";
echo "<surname>" . $sPupilSurname . "</surname>\n";
echo "<forename>" . $sPupilForename . "</forename>\n";
echo "<dob>" . $sPupilDOB . "</dob>\n";
echo "<address>" . $sPupilAddress . "</address>\n";
echo "<contact>" . $sPupilEmergency . "</contact>\n";
echo "<class>" . $sPupilClass . "</class>\n";
echo "</pupil>\n";
// moves to the next record OR runs out of records (hits end of recordset)
$rsMain->MoveNext();
}
//=====================================//
// Concludes Creating XML Formated Code
echo "</pupilinfo>\n";
//=====================================//
// closes the recordset, frees up resources, kills all traces
$rsMain->Close();
$rsMain->Release();
$rsMain = null;
// closes the connection, frees up resources, kills all traces
$adoCon->Close();
$adoCon = null;
?>
And that, I believe, is that.
I really hope that someone can help me out with this, as I may kill someone soon. LOL.
Thanks
TheMightySpud
I'm currently working on a university project to create a small Flash Application for use on a PDA which needs to use PHP and a Database.
Due to security reasons, the University won't let me use a MySQL database, and have insisted on an Access DB, which in itself is a pain, but that's not the problem.
Also, I'm limited to using ActionScript 2.0 again, due to University resources.
My idea is to create a registration system for a school. The plan is as follows.
Upon loading the app, the user (a teacher) is shown a login page.
Login Screen (http://www.st-t.co.uk/nt/screen001.jpg)
Once a username and password are entered, the app then takes you to a registration screen.
Registration Screen (http://www.st-t.co.uk/nt/screen002.jpg)
Which displays all of the School Students that are linked to the class that the teacher is responsible for and displays a dropdown box with a number of options (absent, present, holiday) which will need to be selected on a daily basis (at the start of the day) and the results put into the database. Also on this page there is a 'More' button, which when clicked will take the user to a details page.
Details Screen (http://www.st-t.co.uk/nt/screen003.jpg)
The details page will display all the important information pertaining to the student that has been selected.
I've attached all of the files I have so far to this post, to make it easier for everyone :)
Now, my problem is thus, well, it's more like two problems really.
Firstly, I'm not 100% sure I'm tackling this the correct way, so if anyone knows of a better way to do what I want to do, I would be most grateful of any input. :)
Secondly, the way that I'm dealing with it at the moment is having variables from the login form being passed to the PHP script which performs the query and outputs the results to XML which is then sent back to the Flash app for displaying.
The problem is, that the XML doesn't get passed back to the Flash, and it's beginning to really annoy me, I've been searching around for nearly four weeks, but with no success, and with the deadline for the work only another four weeks away, I need to get it sorted ASAP.
So, onto the Code.
AS2.0 Code. Frame 1 - Stage Elements = Two Input Text boxes and 1 Button
//create varObject for sendingData
var lvoutput:LoadVars = new LoadVars();
lvoutput.Username = txtUsername.text;
lvoutput.Password = txtPassword.text;
//create xmlObject for returnData
var returnedData:XML = new XML();
returnedData.ignoreWhite = true;
returnedData.onLoad = function(success){
if (!success) {
trace("failed to load/find php script");
}else{
//check for error XML or valid XML
trace("PHP Script found");
//parse XML data
trace("Returned XML: "+ newline + returnedData + newline);
}
}
//make call to php script
LoginButton.onPress = function() {
lvoutput.sendAndLoad("ReadDB3.php", returnedData, "POST");
gotoAndPlay(5);
}
stop();
AS2.0 Code. Frame 5 - Stage Elements = One Listboc for displaying the returned data
onEnterFrame = function() {
ListOutput.htmlText = returnedData;
}
stop();
And the PHP (Works fine when sending username & password from HTML Form and outputs correct XML) :
<?php
//=====================================//
// gets data from form, may be an empty string
$sUsername = $_POST["Username"];
$sPassword = $_POST["Password"];
//=====================================//
// Database Section
//=====================================//
// creates a new Common-Object-Model (COM) connection object
$adoCon = new COM("ADODB.Connection");
// the path to the folder holding this PHP script
$sHere = dirname(__FILE__);
// opens the connection using a standard Access connection string
$adoCon->Open("Provider=Microsoft.Jet.OLEDB.4.0; Data Source=$sHere/Registerdbs.mdb");
$sSQL= "SELECT * FROM tblPupilInfo WHERE class LIKE
(SELECT currentclass FROM tblStaffLogin WHERE Username LIKE '$sUsername' and Password LIKE '$sPassword')";
// searches the DB
$rsMain = $adoCon->Execute( $sSQL );
//=====================================//
// Begins Creating XML Formated Code
echo "<?xml version=\"1.0\"?>\n";
echo "<pupilinfo>\n";
//=====================================//
// Assigns Query results to variable for use later
while (!$rsMain->EOF)
{ // gets each of the fields
$sPupilID = $rsMain->Fields("ID")->value;
$sPupilSurname = $rsMain->Fields("Surname")->value;
$sPupilForename = $rsMain->Fields("Forename")->value;
$sPupilDOB = $rsMain->Fields("DOB")->value;
$sPupilAddress = $rsMain->Fields("Address")->value;
$sPupilEmergency = $rsMain->Fields("Emergency Contact")->value;
$sPupilClass = $rsMain->Fields("Class")->value;
//=====================================//
// Continues Creating XML Formated Code
echo "<pupil>\n";
echo "<surname>" . $sPupilSurname . "</surname>\n";
echo "<forename>" . $sPupilForename . "</forename>\n";
echo "<dob>" . $sPupilDOB . "</dob>\n";
echo "<address>" . $sPupilAddress . "</address>\n";
echo "<contact>" . $sPupilEmergency . "</contact>\n";
echo "<class>" . $sPupilClass . "</class>\n";
echo "</pupil>\n";
// moves to the next record OR runs out of records (hits end of recordset)
$rsMain->MoveNext();
}
//=====================================//
// Concludes Creating XML Formated Code
echo "</pupilinfo>\n";
//=====================================//
// closes the recordset, frees up resources, kills all traces
$rsMain->Close();
$rsMain->Release();
$rsMain = null;
// closes the connection, frees up resources, kills all traces
$adoCon->Close();
$adoCon = null;
?>
And that, I believe, is that.
I really hope that someone can help me out with this, as I may kill someone soon. LOL.
Thanks
TheMightySpud