Keep Getting Parse Error

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
youngloopy
Forum Newbie
Posts: 9
Joined: Fri Mar 04, 2005 9:07 am
Location: NC
Contact:

Keep Getting Parse Error

Post by youngloopy »

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

Code: Select all

tags while

Code: Select all

is offline[/color]
User avatar
n00b Saibot
DevNet Resident
Posts: 1452
Joined: Fri Dec 24, 2004 2:59 am
Location: Lucknow, UP, India
Contact:

Post by n00b Saibot »

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

Post by feyd »

if and else being on the same line means nothing.

What's the parse error? I don't see anything blaring..
User avatar
n00b Saibot
DevNet Resident
Posts: 1452
Joined: Fri Dec 24, 2004 2:59 am
Location: Lucknow, UP, India
Contact:

Post by n00b Saibot »

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 »

Sorry 'bout the

Code: Select all

tag didn't see it, first post here. Still getting the error. Thanks for the help anyway.
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

what.. is.. the.. error..?
youngloopy
Forum Newbie
Posts: 9
Joined: Fri Mar 04, 2005 9:07 am
Location: NC
Contact:

Post by youngloopy »

Parse error: parse error, unexpected '{' on line 3
User avatar
JayBird
Admin
Posts: 4524
Joined: Wed Aug 13, 2003 7:02 am
Location: York, UK
Contact:

Post by JayBird »

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 »

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?
User avatar
JayBird
Admin
Posts: 4524
Joined: Wed Aug 13, 2003 7:02 am
Location: York, UK
Contact:

Post by JayBird »

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 »

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

Post by feyd »

you have invisible characters that are being added by dreamweaver into the code. Get a new editor :) seriously.
Post Reply