Hey
Ok still looking for that DR.
Maybe convert is not the correct lingo. Yet I am certain the comments in the ASP script can be coded with PHP.
I did manage to convert some of the .asp scripts and am still looking for assistance to fill in the blanks.
Key = an auto-numbered record number, unique to each DB entry
GroupID = the field identifying who is submitting to the DB
StudText = the field for the student's answer
TutText = the field for the tutor's response
retrieve.asp --> retrieve.php
'start the code to be parsed by the server
<%
'create a connection object - the Connection1 name can be any allowable variable
Set Connection1 = Server.CreateObject("ADODB.Connection")
'create a Recordset object - the Recordset1 name can be any allowable variable
Set Recordset1 = Server.CreateObject("ADODB.Recordset")
'Using the newly created Connection1 object use the OPEN method to
'open an ODBC reference database (see note 1 at the end of this script) whose name in this case is exam
Connection1.Open "exam"
'Create a string variable called SQL and create and set the required SQL statement
'note the breakout to insert the variable passed by the Flash front end
SQL = "SELECT * FROM Table1 WHERE GroupID='" & Request.Form("GroupID") & "';"
'Using the newly created Recordset1 object use the OPEN method to open a recordset
'based on the SQL query defined before from the Database referenced via Connection1
Recordset.Open SQL,Connection1,1,2
'If the recordset contains no data from the outset i.e (EOF - End Of File) then set
'a string variable (StudText) to return this information - note that it also breaks out
'to include the variable from the original Flash form
If Recordset1.EOF Then
StudText = "No Records found for " & request.form("GroupID")
'If not at end of file then query the field information from the recordset
'note that because the GroupID is the key field it does not allow repeats
'so that a populated recordset will only contain one record so we do not
'have to worry about moving around it
Else
GroupID = Recordset1 ("GroupID")
StudText = Recordset1 ("StudText")
TutText = Recordset1 ("TutText")
End If
'House keeping tasks next, although there will be time-outs it is good practice to close
'the recordset and connection objects via the CLOSE methods, as this allows the server
'to get on with new requests rather than waiting
Recordset1.Close
Connection1.Close
'Next we return the retrieved information to the Flash form using the server's response.write function
'note that the variable names defined in the brackets are those which are the name of the text
'boxes on the Flash form. We break out to add the variables we have set
'and we ensure they are sent in the correct format by using the server.URLEncode function
'this converts things like spaces to the required character.
response.write("StudText="+Server.URLEncode(StudText))
response.write("&TutText="+Server.URLEncode(TutText))
response.write("&GroupID="+Server.URLEncode(GroupID))
'end the code
%>
<?php
/Open the connection /
/ include connection information file /
include ( 'dbinfo.php' )
/ MySQL table created to store the data /
$exam = "TabStudDB";
/query the recordset to check if a record for the passed GroupID exists /
$sql = "SELECT * FROM Table1 WHERE GroupID=
$GroupID = Recordset1 ("GroupID")
$StudText = Recordset1 ("StudText")
$TutText = Recordset1 ("TutText")
/ Close the curent recordset using the close method /
MYSQL_CLOSE();
?>
submit.asp --> submit.php
<%
'Open the connection
Set Connection = Server.CreateObject("ADODB.Connection")
Set Recordset = Server.CreateObject("ADODB.Recordset")
Connection.Open "exam"
'query the recordset to check if a record for the passed GroupID exists
SQL = "SELECT * FROM Table1 WHERE GroupID='" & Request.Form("GroupID") & "';"
Recordset.Open SQL,Connection,1,2
'If no records exist then execute the code nested within the If statement
If Recordset.EOF Then
'Close the curent recordset using the close method
Recordset.close
'Create a new SQL statement variable which uses the INSERT command to add the passed variable values
'from the Flash form. Note that we do this in two lines of code, and split them by amending (in
'this case adding to the end of the first SQL_ADD variable) the first variable - this just makes
'it slightly easier to read. Note that we are breaking out in several places to include the
'variables passed from the Flash form.
SQL_ADD = "INSERT INTO Table1(GroupID,StudText,TutText) VALUES('" & Request.Form("GroupID") & "','"
SQL_ADD = SQL_ADD & Request.Form("StudText") & "','" & Request.Form("TutText") & "')"
'we then use the execute method on the created connection object (in our our case called
'"connection") and pass it an SQL statement (as defined before as the SQL_ADD variable)
Connection.Execute (SQL_ADD)
'Again a bit of house keeping to close the connection
Connection.close
'Destroy the Connection object
set connection = nothing
'Return a string to the Flash form to assure the user that something has happened!
Response.write("GroupID=New Group Added " & request.form("GroupID"))
'Otherwise if a record already then amend with the passed data
Else
'Ammend the fields of the opened recordset by passing the form variables to them
'note that there can only be one record in the recordset since the GroupID is
'set to not allow repeats
Recordset.Fields("StudText") = request.form("StudText")
Recordset.Fields("TutText") = request.form("TutText")
'We then update database by using the recordset UPDATE method
Recordset.Update
'Again give some feedback for user assurance that something is going on behind the scenes
Response.write("GroupID=Old Group Amended " & request.form("GroupID"))
'do some housekeeping
Recordset.close
Connection.close
End If
'and we are finished
%>
<?php
/ this script will handle the variables passed from flash file /
/ declare some relevant variables /
/ include connection information file /
include ( 'dbinfo.php' )
/ MySQL table created to store the data /
$exam = "TabStudDB";
/ make connection to database /
MYSQL_CONNECT($dbhost,$dbuser,$dbpass) OR DIE("Unable to connect to database");
@mysql_select_db("$dbName") or die("Unable to select database");
/ query the DB to check if a record for the passed GroupID exists /
$record = mysql_query ($GroupID)
/ If no records exist then execute the code nested within the If statement /
/* Close the curent connection using the close method
MYSQL_CLOSE();
/ Use the INSERT command to add the passed variable values from the Flash form./
/ Insert information into table /
$query = "INSERT INTO $exam VALUES('$GroupID','$StudText', '$TutText')";
/* Close the curent connection using the close method
MYSQL_CLOSE();
/ Return a string to the Flash form to assure the user that something has happened! /
PRINT "Your information has also been inserted into our database, for future reference.";
/ Otherwise if a record already then amend with the passed data /
Else
/ Amend the fields of the opened database by passing the flash variables to them /
/ note that there can only be one record in GroupID it is set to not allow repeats /
/* We then update database by using the UPDATE method */
UPDATE $exam ;
/* Again give some feedback for user assurance that something is going on behind the scenes */
/* Close the curent connection using the close method
MYSQL_CLOSE();
End If
?>
So there you have it.
I have a number of blanks to fill in, possibly have misused some code I did find and have not discovered how to code the missing comments. I have searched php.net and mysql.com and truely am confused as to what I need to make this script run. I did searches for "If Then Else" statements with no luck. Searched for "If record exists" with no luck. (remember I am a newbie coder)
I know this and the submit scripts are very simple scripts. Please assist me with the code so I can learn from a working example. There are just no Flash/PHP/Mysql tutorials out there that I can find and I have a project for work that I must code.
So bottom line....
would someone please provide the correct code for this retrieve.php script? It would be greatly appreciated.
Thanks
Sharon