Link to home
Start Free TrialLog in
Avatar of pearcedn
pearcedn

asked on

creating a database

i have a form which takes the users name,address etc, at the moment it just traces the user info, i would like to put it into a database that will store info, with a view to sharing that info, would it be an xml or php file or what, im not sure, how is it done?
Avatar of henryww
henryww

hi pearcedn,

the complete work? i am afraid it is too long & too complicated to explain it here...

depends on what u are running on the server, for the scripting u can use php, asp ... database - mySQL, access, Ms SQL ... whatever u are family with. but if are new and not too familiar with any of them ... well .. get ultradev and it does most of the coding part for u or search the web for sample codes, they are many sites where u can do straight copy & paste. and i am not going to explain it all in detail ...

//for the flash part, if u are using mx
myVars = new LoadVars();
myVars.name = /:name //or whatever u variable is
myVars.address = /:address
... etc
myVars.send("save.asp","POST");


'for the asp
'open a connection to the database "con"

name = request.form("name")
address = request.form("address")
... etc
sql = "insert into ... (name, address,...) values ('" & name ...
.
.
.
etc

con.execute(sql)

'done

so what u need is a database ready to take the input, the server side scripting (asp, php, perl) to take the form values and insert into the database.

in the flash all u have to do is construct the variables to "POST" and it goes to the form-accepter page, the rest of the programming is done in that form-accepter page.

cheers


oh ... to get the data out of the database is quite similar

a page where it gets the data out of the database and display the info in the following format:

name1=henry+wong&address1=mars&name2=pearcedn&address2=earth


//in the flash
myNewVars = new LoadVars();
myNewVars.load("getData.asp",myNewVars,"POST")

// when the page returns the values
myNewVars.onLoad = function () {
 name1 = myNewVars.name1 // the name1="henry wong"
 address1 = myNewVars.address1 // ... etc ...
 //or u can do a loop to loop thru all values etc etc
}

'for the asp page
'open a connection to the database "con"
sql = "select * from ... ... .. " 
set rs = con.execute (sql);
while not rs.eof
  counter = counter + 1
  response.write "name" & counter & "=" & rs("name")
  respones.write "address" & counter & "=" & rs("address")
wend
..
.
. etc
'done
Avatar of pearcedn

ASKER

ok then what if i just want the data to go into a file, ive started to write an xml file
this is what i have so far
<?xml version="1.0" ?>
<!DOCTYPE database SYSTEM "database.dtd">
<database>
 <firstname></firstname>
 <middleinit></middleinit>
 <lastname></lastname>
 <address></address>
 <city></city>
 <postcode></postcode>
 <phone></phone>
 <comments></comments>
</database>

im a complete newbie when it comes to xml (and everything else for that matter)
so what else has to go into this file to grab the info from my flash page

this is the code on my flash page
stop();
sendData = new LoadVars();
replyData = new LoadVars();
replyData.onLoad = function (success) {
     if (success) {
          trace ("submision was successful!");
     }
}


function submitForm(){
     sendData.firstName = firstName;
     sendData.middleInitial = middleInitial;
     sendData.lastName = lastName;
     sendData.address = address;
     sendData.city = city;
     sendData.postcode = postcode;
     sendData.phone = phone;
     sendData.comments = comments;
     sendData.sendAndLoad("myScript.php", replyData, "POST");
}
as far as i know, flash can only send/save data via HTTP POST or GET ... so u will have to necessary script in the php file to write the xml back on the server

sendData = new XML();
replyData = new XML();
replyData.onLoad = function (success) {
    if (success) {
         trace ("submision was successful!");
    }
}

function submitForm(){
    XMLObject = sendData.createElement("UserRecord");
    XMLObject.attributes.firstName = firstName;
    XMLObject.attributes.middleInitial = middleInitial;
    //... etc

    // POST by default
    sendData.sendAndLoad("myScript.php",replyData);
}


//php - check write permission on the server
<?
$filename = "output.txt";
$fp = fopen( $filename,"w+");
fwrite ( $fp, "$HTTP_RAW_POST_DATA" );
fclose( $fp );
print '<?xml version="1.0"?><result>whatever it is</result>';
?>

i didn't validate or try the code, don't have php on my notebook... well ... it should work
when i put in details i get submission is successful, but nothing has been inserted into this php file, have i written it right?
this file is called myScript.php
where does this output.txt come from?

<?
$filename = "output.txt";
$fp = fopen( $filename,"w+");
fwrite ( $fp, "$HTTP_RAW_POST_DATA" );
fclose( $fp );
print
<?xml version="1.0" ?>
<!DOCTYPE database SYSTEM "database.dtd">
<database>
 <firstname></firstname>
 <middleinitial></middleinitial>
 <lastname></lastname>
 <address></address>
 <city></city>
 <postcode></postcode>
 <phone></phone>
 <comments></comments>
</database>
well ...
<?
$filename = "output.txt";
$fp = fopen( $filename,"w+");
fwrite ( $fp, "$HTTP_RAW_POST_DATA" ); // this line does the write file ...
fclose( $fp );
?>

and make sure u have the write permission for the output.txt
im confused, i want the data that the user inputs to go into an xml database, thats what i have been trying to do with this
<?
$filename = "output.txt";
$fp = fopen( $filename,"w+");
fwrite ( $fp, "$HTTP_RAW_POST_DATA" );
fclose( $fp );
print
<?xml version="1.0" ?>
<!DOCTYPE database SYSTEM "database.dtd">
<database>
<firstname></firstname>
<middleinitial></middleinitial>
<lastname></lastname>
<address></address>
<city></city>
<postcode></postcode>
<phone></phone>
<comments></comments>
</database>
is this right?
where does the output.txt come from?
what is the write permission?
put it in newbie speak and i may understand it!
ASKER CERTIFIED SOLUTION
Avatar of henryww
henryww

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
hes a star!