PDA

View Full Version : undefined index


snail28
09-29-2008, 10:57 AM
i have another problem with my php code,

<?php

//error handler function
function customError($errno, $errstr)
{

echo "<b>Error:</b> [$errno] $errstr";

}

//set error handler
set_error_handler(customError);

//trigger error


$string = $_GET['doc'];
// declare a variable and assign the text sent to this script

$file = fopen('stage1.xml', 'a');
// for the meaning of the second parameter check http://tr2.php.net/fopen
// but this basically opens the file if it exists or creates it. use double
// period for upper directories like "../somefile.txt'

$write = fwrite($file, $string);
// this variable returns false if this file can not be edited.
// parameter1 is the reference of the file, parameter2 is the string to write

if ($write) {
echo "<br>&result=success&</br>";
// use ambersand sign before the variable name and after the value for flash
// and note that whatever the type of value it will be a string in flash
} else {

echo "<br>&result=failure&</br>";
}
fclose($file);
?>


the result is always failure and when i use the error handler the result is
Error: [8] Undefined index: doc

my question is how i can i handle this undefined index ?

i need the solution, i hope anyone can help me.

thanks

yell0wdart
09-29-2008, 11:35 AM
You're getting that exception because the PHP page isn't finding a "doc" name/value pair in your query string. You might want to check for null first, or put that portion of your code in a try/catch block.

snail28
09-29-2008, 12:48 PM
actually i was trying to integrating this php with flash and that 'doc' is an xml object which declared at the flash document that i made..


this.button_mc.onRelease = function(){

doc.contentType = "text/xml";
doc.send("http://server/andy/write.php","_blank","POST");

}


so i was little confuse about how to send this 'doc' in flash so that php could get it.. ?

yell0wdart
09-30-2008, 02:02 AM
I think I may see why you're getting it then. You're sending "doc" to PHP via an http post. In your PHP, you're trying to access it via $_GET['doc']. Try using $_POST['doc'] instead and see if that works.

/edit

You could also try sending to your PHP file by changing "POST" to "GET" in your ActionScript:
doc.send("http://server/andy/write.php", "_blank", "GET");

Since you're trying to send XML via http, though, I'd stick with post. Get would work nicely if you were just sending a name/value through the query string... but XML r srs bidniss. Change $_GET['doc'] to $_POST['doc']. ;)

snail28
10-03-2008, 11:52 AM
thank for the solution,but it's still not working,.. i think there's a mistake in the actionscript like, should i use LoadVars function ?

yell0wdart
10-03-2008, 05:55 PM
Yes. Something like this should work:


myVars = new LoadVars();
myVars.variable1 = "value1";
myVars.variable2 = "value2";
// add more as needed
myVars.send("**url to your page goes here**", "_self", "POST");

snail28
10-06-2008, 05:38 AM
im sorry for always asking and maybe it's disturb you..but i still don't get the problem solution while i've changed the actionscript, like this..

// create an XML document
var doc:XML = new XML();

//create an new loadvars
var myvar:LoadVars = new LoadVars();


// create three XML nodes using createElement()
var element1:XMLNode = doc.createElement("level");

// place the new nodes into the XML tree
doc.appendChild(element1);
element1.appendChild(element2);

myvar.docdata = doc;

listenerKey.onKeyDown = function(){

//save data into variable
Rec.keycode = Key.getCode().toString();
Rec.beatTime = (getTimer() / 100).toString();
dataRec.push(Rec);

var keycode_node:XMLNode = doc.createElement("keyCode");
keycode_node.appendChild( doc.createTextNode( Rec.keycode ) );

var beatTime_node:XMLNode = doc.createElement("beatTime");
beatTime_node.appendChild( doc.createTextNode( Rec.beatTime ) );

//place data into xml tree
element1.appendChild(keycode_node)
element1.appendChild(beatTime_node)
trace (doc);


}



this.button_mc.onRelease = function(){

myvar.contentType = "text/xml";
myvar.send("http://server/andy/write.php","_blank","POST");

}


the bolded part is the part of the code that i've changed..what do you think about it ?

please accept my thanks and sorry maybe for disturbing you :)

yell0wdart
10-06-2008, 06:01 AM
Not a problem at all.

Not sure how this works in AS2 in regard to value types vs reference types, but you're basically adding the empty XML document to the LoadVars object, then building the document. Have you tried building the document first, then adding it to the LoadVars object?

When you do your trace(doc);, does it return the XML in the output window? If not, try building your doc first, then doing the mydoc.docData = doc; inside your event handler (right before the trace()).

snail28
10-06-2008, 06:23 AM
actually i've already build the 'stage1.xml' document and i can open it..and when i do the trace(doc) it return the xml in the output window.. like this

*it's when i press 'A'
<level><keyCode>65</keyCode><beatTime>4.84</beatTime></level>

but all i want to do is to send the xml result in the flash and saved the result into the xml document so i have an xml document which contain the xml result..it's like that,can you get it ?

yell0wdart
10-06-2008, 07:48 PM
Wait. So you're not trying to send XML though the http request, then. Based on your description, you're saving the XML document, then trying to load it in your PHP?

snail28
10-07-2008, 03:15 AM
actually..im trying so use php to save the XML object into an XML document, so it's like i use fwrite function in the php because i want the XML result to be saved in document..it is the same like what you thought ? hmm..do you have any YM ? maybe we can have a little conversation so it will be easier ?

CobaltBlueDW
10-07-2008, 04:40 AM
"myvar.docdata = doc;" should be something like "myvar.doc = doc.toString();"

Otherwise it attaches the XML document to the LoadVars object, and LoadVars doesn't transport Objects like that.

snail28
10-07-2008, 06:27 AM
ok thanks again for another solution, maybe i'll try it now..but i don't think it can solve all of my problem :(

snail28
10-08-2008, 04:20 AM
it doesn't work anyway..i feel desperate about this problem..is anyone here can help me with other solution to write the xml object that i have into an xml document ?

yell0wdart
10-10-2008, 10:43 PM
Not sure what to tell ya. Maybe check this article out and see if you can put some of those practices to use:

http://www.experts-exchange.com/Web_Development/Web_Languages-Standards/PHP/Q_23746891.html