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
calmchess
Forum Commoner
Posts: 33 Joined: Fri Aug 18, 2006 8:14 pm
Post
by calmchess » Mon Sep 04, 2006 12:57 pm
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);
?>
Mordred
DevNet Resident
Posts: 1579 Joined: Sun Sep 03, 2006 5:19 am
Location: Sofia, Bulgaria
Post
by Mordred » Mon Sep 04, 2006 1:00 pm
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 » Mon Sep 04, 2006 1:21 pm
all of line 3 contains parse errors.....if i remove line 3 then line 5 gets a parse error
volka
DevNet Evangelist
Posts: 8391 Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger
Post
by volka » Mon Sep 04, 2006 1:28 pm
$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.
feyd
Neighborhood Spidermoddy
Posts: 31559 Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA
Post
by feyd » Mon Sep 04, 2006 1:32 pm
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 » Mon Sep 04, 2006 1:34 pm
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 » Mon Sep 04, 2006 3:23 pm
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);
?>
feyd
Neighborhood Spidermoddy
Posts: 31559 Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA
Post
by feyd » Mon Sep 04, 2006 4:02 pm
Be careful with blindly accepting submission values. It'd be pretty simple for someone to submit garbage to your script.