php parse error help me!

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
calmchess
Forum Commoner
Posts: 33
Joined: Fri Aug 18, 2006 8:14 pm

php parse error help me!

Post 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
User avatar
Mordred
DevNet Resident
Posts: 1579
Joined: Sun Sep 03, 2006 5:19 am
Location: Sofia, Bulgaria

Re: php parse error help me!

Post 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().
Last edited by Mordred on Mon Sep 04, 2006 2:10 pm, edited 2 times in total.
calmchess
Forum Commoner
Posts: 33
Joined: Fri Aug 18, 2006 8:14 pm

Post by calmchess »

all of line 3 contains parse errors.....if i remove line 3 then line 5 gets a parse error
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Post 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.
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

What's the intention of using echo in this snippet?
calmchess
Forum Commoner
Posts: 33
Joined: Fri Aug 18, 2006 8:14 pm

Post 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.
calmchess
Forum Commoner
Posts: 33
Joined: Fri Aug 18, 2006 8:14 pm

Post 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);
?>
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

Be careful with blindly accepting submission values. It'd be pretty simple for someone to submit garbage to your script.
Post Reply