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
youngloopy
Forum Newbie
Posts: 9 Joined: Fri Mar 04, 2005 9:07 am
Location: NC
Contact:
Post
by youngloopy » Fri Mar 04, 2005 9:13 am
I am getting a parse error on line 3. Can anyone tell me why I've tried everything. I am very new at this so bear with me.
Code: Select all
<?php
if ($_POSTї'pw']!="") {$pw=$_POSTї'pw'];}else{$pw=$_GETї'pw'];}
$newcontent=$_POSTї'newcontent'];
$filelocation = "test.txt";
if (!file_exists($filelocation)) {
echo "Couldn't find datafile, please contact administrator!";
}
else {
$newfile = fopen($filelocation,"r");
$content = fread($newfile, filesize($filelocation));
fclose($newfile);
}
$content = stripslashes($content);
$content = htmlentities($content);
$pass="password";
if (!$pw || $pw != $pass){
$content = nl2br($content);
echo $content;
}
else {
if ($newcontent){
$newcontent = stripslashes($newcontent);
$newfile = fopen($filelocation,"w");
fwrite($newfile, $newcontent);
fclose($newfile);
echo 'Text was edited.<form><input type="submit"
value="see changes" /></form>';
}
else{
echo '<form method="post">
<textarea name="newcontent" cols="50"
rows="15" wrap="virtual">';
echo $content;
echo "</textarea>
<input type="hidden" name="pw"
value="'.$pass.'" />
<br /><input type="submit" value="edit" />
</form>';
}
}
?>
feyd | please use
n00b Saibot
DevNet Resident
Posts: 1452 Joined: Fri Dec 24, 2004 2:59 am
Location: Lucknow, UP, India
Contact:
Post
by n00b Saibot » Fri Mar 04, 2005 9:16 am
First off, post your code using code tags provided. you may want to edit your post now to correct this.
Now, you have if and else on the same line. fixing that may help.
feyd
Neighborhood Spidermoddy
Posts: 31559 Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA
Post
by feyd » Fri Mar 04, 2005 9:17 am
if and else being on the same line means nothing.
What's the parse error? I don't see anything blaring..
n00b Saibot
DevNet Resident
Posts: 1452 Joined: Fri Dec 24, 2004 2:59 am
Location: Lucknow, UP, India
Contact:
Post
by n00b Saibot » Fri Mar 04, 2005 9:30 am
Are you sure you have the variable named pw. because that is the only error that could happen otherwise code seems ok.
Feyd! :lol:This is the thing that happens when one is working late and has to deal with 3 languages at same time. Ooo! I m off ! Good Night!
youngloopy
Forum Newbie
Posts: 9 Joined: Fri Mar 04, 2005 9:07 am
Location: NC
Contact:
Post
by youngloopy » Fri Mar 04, 2005 9:46 am
Sorry 'bout the
Code: Select all
tag didn't see it, first post here. Still getting the error. Thanks for the help anyway.
feyd
Neighborhood Spidermoddy
Posts: 31559 Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA
Post
by feyd » Fri Mar 04, 2005 9:51 am
what.. is.. the.. error..?
youngloopy
Forum Newbie
Posts: 9 Joined: Fri Mar 04, 2005 9:07 am
Location: NC
Contact:
Post
by youngloopy » Fri Mar 04, 2005 9:55 am
Parse error: parse error, unexpected '{' on line 3
JayBird
Admin
Posts: 4524 Joined: Wed Aug 13, 2003 7:02 am
Location: York, UK
Contact:
Post
by JayBird » Fri Mar 04, 2005 9:58 am
the only parse error i can see is at the end of the script
Code: Select all
echo "</textarea>
<input type="hidden" name="pw"
value="'.$pass.'" />
<br /><input type="submit" value="edit" />
</form>';
should be
Code: Select all
echo "</textarea>
<input type="hidden" name="pw"
value="'.$pass.'" />
<br /><input type="submit" value="edit" />
</form>";
notice the single and double quotes starting and ending the string
youngloopy
Forum Newbie
Posts: 9 Joined: Fri Mar 04, 2005 9:07 am
Location: NC
Contact:
Post
by youngloopy » Fri Mar 04, 2005 10:21 am
Thanks, I missed that but I can't get past the error in line 3. I don't see the unexpected '{' that it keeps seeing. Do you?
JayBird
Admin
Posts: 4524 Joined: Wed Aug 13, 2003 7:02 am
Location: York, UK
Contact:
Post
by JayBird » Fri Mar 04, 2005 10:28 am
nope, all looks good to me.
Is that all the code or is there anymore before it?
youngloopy
Forum Newbie
Posts: 9 Joined: Fri Mar 04, 2005 9:07 am
Location: NC
Contact:
Post
by youngloopy » Fri Mar 04, 2005 10:50 am
Thats it, nothing else before it, I have no idea what's wrong. But now I pasted it into dreamweaver as a .php just to see and now it says Parse error: parse error, unexpected T_STRING in line 2...but there is nothing on line 2.
feyd
Neighborhood Spidermoddy
Posts: 31559 Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA
Post
by feyd » Fri Mar 04, 2005 10:56 am
you have invisible characters that are being added by dreamweaver into the code. Get a new editor
seriously.