Page 1 of 1

php parse error help me!

Posted: Mon Sep 04, 2006 12:57 pm
by calmchess
The following code creates a php parse error on line 3 ($toSave = echo"<?xml version=\"1.0\"?>\n","<products>\n", "<item>" . $listings . "</item>\n","</products>\n";)
I can't figure out how to debug it ...could somebody help me please.

Code: Select all

<?php
$listings = $_POST['myTextVar'];
$toSave = echo"<?xml version=\"1.0\"?>\n","<products>\n", "<item>" . $listings . "</item>\n","</products>\n";
$fp = fopen("sendsave.txt", "w");
if (fwrite($fp, $toSave, )) {
echo "writing=Ok";
}else {
echo "writing=Error";
}
fclose($fp);
?>
8O

Re: php parse error help me!

Posted: Mon Sep 04, 2006 1:00 pm
by Mordred

Code: Select all

,"<products>

Code: Select all

."<products>


Debug such things by breaking the line in several chunks each on a new line and seeing which chunk contains the error


Edit: I stand corrected, comma and dot will both work for echo().

Posted: Mon Sep 04, 2006 1:21 pm
by calmchess
all of line 3 contains parse errors.....if i remove line 3 then line 5 gets a parse error

Posted: Mon Sep 04, 2006 1:28 pm
by volka
$toSave = echo "<?xml version=\"1.0\"?>\n","<products>\n", "<item>" . $listings . "</item>\n","</products>\n";
what's that supposed to do? echo does not return anything but sends output to the client.
if (fwrite($fp, $toSave, )) {
The comma causes the parse error.

Posted: Mon Sep 04, 2006 1:32 pm
by feyd
What's the intention of using echo in this snippet?

Posted: Mon Sep 04, 2006 1:34 pm
by calmchess
here is what i want to do i want to save everything after echo to a text file....... $listings is a variable which contains text that is passed to the php page by a flash page.

Posted: Mon Sep 04, 2006 3:23 pm
by calmchess
I found the solution to my problem thanks for your support.....here is the working code if anybody is intreasted.

>>>>>>>>>>>flash sends data to php file via $listings variable>>>>>>>>>>>php saves data within xml tags inside a text file.

note: the anastasio.txt file is overwritten each time the php script runs

Code: Select all

<?php
$listings = $_POST['myTextVar'];
$toSave =  "<?xml version=\"1.0\"?>\n<products>\n <item>\n  $listings  </item>\n </products>\n";

$fp = fopen("anastasio.txt", "w");

if (fwrite($fp, $toSave)) {
echo "writing=Ok";
}else {
echo "writing=Error";
}
fclose($fp);
?>

Posted: Mon Sep 04, 2006 4:02 pm
by feyd
Be careful with blindly accepting submission values. It'd be pretty simple for someone to submit garbage to your script.