Page 1 of 1

Keep Getting Parse Error

Posted: Fri Mar 04, 2005 9:13 am
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]

Posted: Fri Mar 04, 2005 9:16 am
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.

Posted: Fri Mar 04, 2005 9:17 am
by feyd
if and else being on the same line means nothing.

What's the parse error? I don't see anything blaring..

Posted: Fri Mar 04, 2005 9:30 am
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!

Posted: Fri Mar 04, 2005 9:46 am
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.

Posted: Fri Mar 04, 2005 9:51 am
by feyd
what.. is.. the.. error..?

Posted: Fri Mar 04, 2005 9:55 am
by youngloopy
Parse error: parse error, unexpected '{' on line 3

Posted: Fri Mar 04, 2005 9:58 am
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

Posted: Fri Mar 04, 2005 10:21 am
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?

Posted: Fri Mar 04, 2005 10:28 am
by JayBird
nope, all looks good to me.

Is that all the code or is there anymore before it?

Posted: Fri Mar 04, 2005 10:50 am
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.

Posted: Fri Mar 04, 2005 10:56 am
by feyd
you have invisible characters that are being added by dreamweaver into the code. Get a new editor :) seriously.