Results 1 to 38 of 38

Thread: [RESOLVED] Parse error again..

  1. #1

    Thread Starter
    Admodistrator |2eM!x's Avatar
    Join Date
    Jan 2005
    Posts
    3,900

    Resolved [RESOLVED] Parse error again..

    PHP Code:
    <html>
    <h3>Testing Stuff</h3>
        <form method = "POST" action ="<?php echo $_SERVER['PHP_SELF'];?>"
        <input type = "hidden" name = "send" value = "1">
        <p>Username:<input type="text" name="UserName" /></p>
        <p>Password:<input type="text" name="Password" /></p>
        <input type="submit" value ="Login" />
    </form>
    <body background="http://users.pandora.be/creeping_death/Babes/Anna%20Kournikova%2002.jpg">
        <?php
        
    If ($_POST[send] == "1"){
            
    $Filename $_POST[UserName];
                If (
    file_exists($Filename)){
                    
    $handle fopen($Filename"r") or die("Error Reading");
                    
    $contents = @fread($handle,filesize($Filename)) or die("Error2");
                    
    fclose($handle);
                    If (
    $contents == $_POST[Password]){
                        echo 
    "</br>.Logged in";
                    }else{
                        echo 
    "Invalid password";
                    }

                [
    B]}else{[/B]
                    
    $handle fopen($Filename"w") or die ("Error writing");
                    
    $contents = @fwrite($handle,$_POST[Password];
                    
    fclose($handle);
                }            
    ?>
    </html>
    says error on line 25, and i really dont see anything wrong there

  2. #2
    Frenzied Member oceanebelle's Avatar
    Join Date
    Jun 2005
    Location
    my n00k.
    Posts
    1,064

    Re: Parse error again..

    is the error on the supposed to be bolded part else?

  3. #3
    Frenzied Member oceanebelle's Avatar
    Join Date
    Jun 2005
    Location
    my n00k.
    Posts
    1,064

    Re: Parse error again..

    I think you have forgot to close fwrite function? on teh else part.

  4. #4
    Frenzied Member oceanebelle's Avatar
    Join Date
    Jun 2005
    Location
    my n00k.
    Posts
    1,064

    Re: Parse error again..

    and I'm not seeing the closing parenthesis of your very first if. block

  5. #5

    Thread Starter
    Admodistrator |2eM!x's Avatar
    Join Date
    Jan 2005
    Posts
    3,900

    Re: Parse error again..

    Code:
        If ($_POST[send] == "1"){
            $Filename = $_POST[UserName];
                If (file_exists($Filename)){
                    $handle = fopen($Filename, "r") or die("Error Reading");
                    $contents = @fread($handle,filesize($Filename)) or die("Error2");
                    fclose($handle);
                    If ($contents == $_POST[Password]){
                        echo "</br>.Logged in";
                    }else{
                        echo "Invalid password";
                    }
    
                }else{
                    $handle = fopen($Filename, "w") or die ("Error writing");
                    $contents = @fwrite($handle,$_POST[Password];
                    fclose($handle);
                } 
    Also, what did you mean i am not closing my fwrite?
    $contents = @fwrite($handle,$_POST[Password];
    fclose($handle);

  6. #6
    Frenzied Member oceanebelle's Avatar
    Join Date
    Jun 2005
    Location
    my n00k.
    Posts
    1,064

    Re: Parse error again..

    $contents = @fwrite($handle,$_POST[Password]); <<-- closing parenthesis

  7. #7

    Thread Starter
    Admodistrator |2eM!x's Avatar
    Join Date
    Jan 2005
    Posts
    3,900

    Re: Parse error again..

    OB, can i ask one more:
    PHP Code:
    <html>
        <h3>Testing Site</h3>
        <form method = "POST" action = "<?php echo $_SERVER['PHP_SELF'];?>"
        <input type = "hidden" name = "hidden" value = "1"/>
        <p>UserName<input type = "text" name = "UserName"/></p>
        <p>Password<input type = "text" name = "Password"/></p>
        </form>
    <body background="http://users.pandora.be/creeping_death/Babes/Anna%20Kournikova%2002.jpg>
    <?php
        
    If($_POST[hidden]=="1"){
            
    $filename $_POST[UserName.".html"]
                If(
    file_exists($filename)){
                  
    $handle fopen($filename,"r") or die("Err1")
                  
    $contents = @fread($handle,filesize($filename))
                  
    flcose($handle)
                }Else{
                    If(
    $contents ==$_POST[Password]){
                      echo 
    "Logged in"
                      
    }Else{
                      echo 
    "Invalid password"
                    
    }
                 echo 
    "Username created!"
                 
    $handle fopen($filename,"w") or die("Err2")
                 
    fwrite($handle,$_POST[Password])
                }
        }
    ?>
    Its giving me this error:
    Parse error: syntax error, unexpected T_IF in C:\Documents and Settings\Jason\My Documents\PHP\Login Script\_debug_tmp.php on line 12

    line 12= If(file_exists($filename)){

    So i dont know whats wrong (whats new )

  8. #8
    Hyperactive Member ninjanutz's Avatar
    Join Date
    Jun 2005
    Location
    Bayside
    Posts
    256

    Re: Parse error again..

    jason i heart u

  9. #9
    Hyperactive Member ninjanutz's Avatar
    Join Date
    Jun 2005
    Location
    Bayside
    Posts
    256

    Re: Parse error again..

    u forgot to put the ; after everything, try doin that

  10. #10

    Thread Starter
    Admodistrator |2eM!x's Avatar
    Join Date
    Jan 2005
    Posts
    3,900

    Re: Parse error again..

    okay got everything almost working.

    PHP Code:
    <html>
        <h3>Testing Site</h3>
        <form method = "POST" action = "<?php echo $_SERVER['PHP_SELF'];?>"
        <input type = "hidden" name = "send" value = "1">
        <p>UserName<input type = "text" name = "UserName"/></p>
        <p>Password<input type = "text" name = "Password"/></p>
        <input type="submit" value ="Login" />
        </form>
    <body background="http://users.pandora.be/creeping_death/Babes/Anna%20Kournikova%2002.jpg">
    </body>
    <?php
        
    If($_POST[send]=="1"){
            
    $filename $_POST[UserName.".txt"];
                If(
    file_exists($filename)){
                  
    $handle fopen($filename,"r") or die("Err1");
                  
    $contents = @fread($handle,filesize($filename));
                  
    fclose($handle);
                }Else{
                    If(
    $contents ==$_POST[Password]){
                      echo 
    "Logged in";
                      }Else{
                      echo 
    "Invalid password";
                    }
                 echo 
    "Username created!";
                 
    $handle fopen($filename,"w") or die("Err2");
                 
    fwrite($handle,$_POST[Password]);
                 
    fclose($handle);
                }
        }
    ?>
    </html>
    I keep getting errors on this line: If($_POST[send]=="1"){
    Notice: Use of undefined constant send - assumed 'send' in C:\Documents and Settings\Jason\My Documents\PHP\Login Script\_debug_tmp.php on line 12 Notice: Undefined index: send in C:\Documents and Settings\Jason\My Documents\PHP\Login Script\_debug_tmp.php on line 12

  11. #11
    Frenzied Member oceanebelle's Avatar
    Join Date
    Jun 2005
    Location
    my n00k.
    Posts
    1,064

    Re: Parse error again..

    perhaps send needs to be a string...
    I really thought that in that context.. and send being used that way... it will look for a constant variable.. which is not defined. and perhaps that's where the error goes...

    I would use this.. instead of that.
    If($_POST['send']=="1"){

    or
    If($_POST["send"]=="1"){

  12. #12

    Thread Starter
    Admodistrator |2eM!x's Avatar
    Join Date
    Jan 2005
    Posts
    3,900

    Re: Parse error again..

    Okay thanks, but now this part is still there:

    Notice: Undefined index: send in C:\Documents and Settings\Jason\My Documents\PHP\Login Script\_debug_tmp.php on line 12

    I dont understand that..Also, whats the difference between using [name] and ['name] and ["name"]

  13. #13
    Frenzied Member oceanebelle's Avatar
    Join Date
    Jun 2005
    Location
    my n00k.
    Posts
    1,064

    Re: Parse error again..

    may I comment on this code fragment?

    $filename = $_POST[UserName.".txt"];

    are you sure about this one?.. this will definitely give you a very weird output.

    i think the right one would be.

    $filename = $_POST[UserName].".txt";

    notice how the ".txt" is moved outside of the brackets?.... I think this is what you want.. 'cause I don't see you posting a value for.... someusername.txt

  14. #14

    Thread Starter
    Admodistrator |2eM!x's Avatar
    Join Date
    Jan 2005
    Posts
    3,900

    Re: Parse error again..

    yes you are right, im still a beginner with php..just learning.

    Thanks, but im still getting that dumb error^^

  15. #15
    Frenzied Member oceanebelle's Avatar
    Join Date
    Jun 2005
    Location
    my n00k.
    Posts
    1,064

    Re: Parse error again..

    I think $_POST['send'] and $_POST["send"] is pretty much the same.. they delimit strings... now if you had posted a value like... send'ed your way of accessing the value would have be $_POST["send'ed"] and vice versa..

    now for $_POST[send] I read at the dox.. and perhaps it is the right one.. but better ask the gurus for this one... that.. the send part here will be accessing a constant variable.. that is defined this way on the file or else where (just included it)...

    define("send", "somesendvalue");

    so the $_POST[send] in my example would actually be accessing like
    $_POST["somesendvalue"]

    well at least that is my understanding of... it. I do hope that someone could clear this up.

  16. #16
    Frenzied Member oceanebelle's Avatar
    Join Date
    Jun 2005
    Location
    my n00k.
    Posts
    1,064

    Re: Parse error again..

    I guess my theory holds on the send... I think it is looking up a constant value... perhaps you could try to change all send variable that you want?

  17. #17
    Frenzied Member oceanebelle's Avatar
    Join Date
    Jun 2005
    Location
    my n00k.
    Posts
    1,064

    Re: Parse error again..

    Just try to change all you $_POST statement... like the send, UserName, Password... enclosed in string delimiters(am I using the right term).. and see from there?

  18. #18
    Frenzied Member oceanebelle's Avatar
    Join Date
    Jun 2005
    Location
    my n00k.
    Posts
    1,064

    Re: Parse error again..

    Quote Originally Posted by ninjanutz
    jason i heart u
    who is jason?

  19. #19

    Thread Starter
    Admodistrator |2eM!x's Avatar
    Join Date
    Jan 2005
    Posts
    3,900

    Re: Parse error again..

    Thanks again

    PHP Code:
    <html>
        <h3>Testing Site</h3>
        <form method = "POST" action = "<?php echo $_SERVER['PHP_SELF'];?>"
        <input type = "hidden" name = "send" value = "1">
        <p>UserName<input type = "text" name = "UserName"/></p>
        <p>Password<input type = "text" name = "Password"/></p>
        <input type="submit" value ="Login" />
        </form>
    <body background="http://users.pandora.be/creeping_death/Babes/Anna%20Kournikova%2002.jpg">
    </body>
    <?php
        
    If($_POST['send']=="1"){
             
    $filename $_POST['UserName'].".txt";
                If(
    file_exists($filename)){
                  
    $handle fopen($filename,"r") or die("Err1");
                  
    $contents = @fread($handle,filesize($filename));
                  
    fclose($handle);
                }Else{
                    If(
    $contents ==$_POST['Password']){
                      echo 
    "Logged in";
                      }Else{
                      echo 
    "Invalid password";
                    }
                 echo 
    "Username created!";
                 
    $handle fopen($filename,"w") or die("Err2");
                 
    fwrite($handle,$_POST['Password']);
                 
    fclose($handle);
                }
        }
    ?>
    </html>
    Still the same error on line 12 (index error)

  20. #20
    Frenzied Member oceanebelle's Avatar
    Join Date
    Jun 2005
    Location
    my n00k.
    Posts
    1,064

    Re: Parse error again..

    Quote Originally Posted by error
    I keep getting errors on this line: If($_POST[send]=="1"){
    Notice: Use of undefined constant send - assumed 'send' in C:\Documents and Settings\Jason\My Documents\PHP\Login Script\_debug_tmp.php on line 12 Notice: Undefined index: send in C:\Documents and Settings\Jason\My Documents\PHP\Login Script\_debug_tmp.php on line 12
    ahh I see it now.. it IS definitely looking for a constant value send... so my theory holds.

  21. #21
    Frenzied Member oceanebelle's Avatar
    Join Date
    Jun 2005
    Location
    my n00k.
    Posts
    1,064

    Re: Parse error again..

    really? hmm.. weird..

    well on my code.. I used.. the " and didn't get to try ' actually... I wonder if that would do it.... have you refreshed everything?? saved everything.?

  22. #22
    Frenzied Member oceanebelle's Avatar
    Join Date
    Jun 2005
    Location
    my n00k.
    Posts
    1,064

    Re: Parse error again..

    Uhmmm I just noticed.. in your opening tag for FORM.. there is not closing > would that be alright?

    perhaps the form did not get submitted or something.

  23. #23

    Thread Starter
    Admodistrator |2eM!x's Avatar
    Join Date
    Jan 2005
    Posts
    3,900

    Re: Parse error again..

    Yes, ive tried both and none resolve im stumped

  24. #24
    Frenzied Member oceanebelle's Avatar
    Join Date
    Jun 2005
    Location
    my n00k.
    Posts
    1,064

    Re: Parse error again..

    I'm stumped as well.

    I have a question though.. is it okey to have the FORM elements. outside of body... I mean.. all the input elements would not show up in the form right?
    I always thougth that forms should be w/n or perhaps I always thougth wrong.

  25. #25
    Frenzied Member oceanebelle's Avatar
    Join Date
    Jun 2005
    Location
    my n00k.
    Posts
    1,064

    Re: Parse error again..

    I'm going to try this one here locally.

  26. #26
    Frenzied Member oceanebelle's Avatar
    Join Date
    Jun 2005
    Location
    my n00k.
    Posts
    1,064

    Re: Parse error again..

    HEEY!!!!.. HOW COME IT WORKED ON MINE... and I didn't even change the code.. the last one that is.

  27. #27
    Frenzied Member oceanebelle's Avatar
    Join Date
    Jun 2005
    Location
    my n00k.
    Posts
    1,064

    Re: Parse error again..

    and disregard my other question.. I found out that your page indeed worked.. I learn new things everyday. tnx.

  28. #28

    Thread Starter
    Admodistrator |2eM!x's Avatar
    Join Date
    Jan 2005
    Posts
    3,900

    Re: Parse error again..

    can i see the code you tried?

  29. #29
    Frenzied Member oceanebelle's Avatar
    Join Date
    Jun 2005
    Location
    my n00k.
    Posts
    1,064

    Talking Re: Parse error again..

    sure! here it is...

    I changed the file location.. so that I can just look at the c root and see if indeed the file got created.. and it did.

    PHP Code:

    <html> 
        <h3>Testing Site</h3> 
        <form method = "POST" action = "<?php echo $_SERVER['PHP_SELF'];?>"> 
        <input type = "hidden" name = "send" value = "1"> 
        <p>UserName<input type = "text" name = "UserName"/></p> 
        <p>Password<input type = "text" name = "Password"/></p> 
        <input type="submit" value ="Login" /> 
        </form> 
    <body background="http://users.pandora.be/creeping_death/Babes/Anna%20Kournikova%2002.jpg"> 
    </body> 
    <?php 
        
    If($_POST['send']=="1"){ 
             
    $filename "c:\\".$_POST['UserName'].".txt"
                If(
    file_exists($filename)){ 
                  
    $handle fopen($filename,"r") or die("Err1"); 
                  
    $contents = @fread($handle,filesize($filename)); 
                  
    fclose($handle); 
                }Else{ 
                    If(
    $contents ==$_POST['Password']){ 
                      echo 
    "Logged in"
                      }Else{ 
                      echo 
    "Invalid password"
                    } 
                 echo 
    "Username created!"
                 
    $handle fopen($filename,"w") or die("Err2"); 
                 
    fwrite($handle,$_POST['Password']); 
                 
    fclose($handle); 
                } 
        } 
    ?> 
    </html>

  30. #30
    Frenzied Member oceanebelle's Avatar
    Join Date
    Jun 2005
    Location
    my n00k.
    Posts
    1,064

    Re: Parse error again..

    Oh!!!.. I did... I did added a the closing > for the opening tag... for it to work.

    so now that code works for me.

    I was right in assuming that the first code did not got submitted because the form tag was malformed.

  31. #31

    Thread Starter
    Admodistrator |2eM!x's Avatar
    Join Date
    Jan 2005
    Posts
    3,900

    Re: Parse error again..

    Same error as before??
    Notice: Undefined index: send in C:\Documents and Settings\Jason\My Documents\PHP\Login Script\_debug_tmp.php on line 12

    And also, if i run it differently (Im using php Designer 2005 IDE) the submit field doesnt remain on the first page

  32. #32
    Frenzied Member oceanebelle's Avatar
    Join Date
    Jun 2005
    Location
    my n00k.
    Posts
    1,064

    Re: Parse error again..

    hmmm.. I wonder why... I edited it at notepad, pasted it on htdocs root.. then opened a browser.. pointed it to the page.. and it worked fine. perhaps php designer not refreshing or something.

  33. #33
    Frenzied Member oceanebelle's Avatar
    Join Date
    Jun 2005
    Location
    my n00k.
    Posts
    1,064

    Re: Parse error again..

    I'm sorry I can't do nothing more than that... it is working well here

    in fact.. it even works fine without them string delimiters.

  34. #34

    Thread Starter
    Admodistrator |2eM!x's Avatar
    Join Date
    Jan 2005
    Posts
    3,900

    Re: Parse error again..

    Well, it works in xampp but not this ide..Guess i should get a better IDE.

    Also, im getting this error when creating password and stuff on line 25
    $handle = fopen($filename,"w") or die("Err2");
    Warning: fopen(|2eM!x.txt): failed to open stream: Invalid argument in C:\PHP\xampp\htdocs\xampp\newform.php on line 25
    Err2

  35. #35
    Frenzied Member oceanebelle's Avatar
    Join Date
    Jun 2005
    Location
    my n00k.
    Posts
    1,064

    Re: Parse error again..

    Perhaps... the file name shouldn't have invalid characters like..| or ! ???

  36. #36
    Frenzied Member oceanebelle's Avatar
    Join Date
    Jun 2005
    Location
    my n00k.
    Posts
    1,064

    Re: Parse error again..

    why can't you give it a simpler name??? it worked fine here. lol my names are like 1 and 2.. so that would be 1.txt and 2.txt... it was generated.

    and go get a better IDE.

  37. #37

    Thread Starter
    Admodistrator |2eM!x's Avatar
    Join Date
    Jan 2005
    Posts
    3,900

    Re: Parse error again..

    That makes sense. Thankyou oceanbelle for helping me!

  38. #38
    Frenzied Member oceanebelle's Avatar
    Join Date
    Jun 2005
    Location
    my n00k.
    Posts
    1,064

    Re: [RESOLVED] Parse error again..

    glad to help.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width