Results 1 to 9 of 9

Thread: If statement help:

  1. #1

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

    If statement help:

    PHP Code:
        <?php
                
    [B]If(($_POST['R\W']) == 'r'){[/B]
            
    $contents = @fopen($_POST['file'], "r") or die("Error opening1");
            
    $reading fread($contentsfilesize($_POST['file'])) or die("Error Reading");
            @
    fclose($_POST['file']);
                echo 
    $_POST['file'],"/n",$reading;
                } Else {    
            
    $contents = @fopen($_POST['file'], "w") or die("Error opening2");
            @
    fwrite($contents,"New file created") or die("Error writing");
            @
    fclose($_POST['file']);
                }
        
    ?>
    How do i check posts value? seems im doing it wrong-it always goes to elses, even if $_POST['R\W'] does equal r

    thanks

  2. #2
    VBA Nutter visualAd's Avatar
    Join Date
    Apr 2002
    Location
    Ickenham, UK
    Posts
    4,906

    Re: If statement help:

    Have you tried checkign the variable contains what you expect it to contain? Try this at the beginningof your script, does it output what you expect?
    PHP Code:
    echo($_POST['R\W']); 
    PHP || MySql || Apache || Get Firefox || OpenOffice.org || Click || Slap ILMV || 1337 c0d || GotoMyPc For FREE! Part 1, Part 2

    | PHP Session --> Database Handler * Custom Error Handler * Installing PHP * HTML Form Handler * PHP 5 OOP * Using XML * Ajax * Xslt | VB6 Winsock - HTTP POST / GET * Winsock - HTTP File Upload

    Latest quote: crptcblade - VB6 executables can't be decompiled, only disassembled. And the disassembled code is even less useful than I am.

    Random VisualAd: Blog - Latest Post: When the Internet becomes Electricity!!


    Spread happiness and joy. Rate good posts.

  3. #3

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

    Re: If statement help:

    thanks visualad, i didnt know php was case sensitive (r\w) was what it was.
    Can you please explain how id add a new line to an echo?

  4. #4
    VBA Nutter visualAd's Avatar
    Join Date
    Apr 2002
    Location
    Ickenham, UK
    Posts
    4,906

    Re: If statement help:

    You need to use a string in double qutoes. For a widnows newline you need a carridge return and line feed, for unix yujust need a line feed:
    Code:
    echo("\r\n"); //windows
    echo("\n"); // unix
    PHP || MySql || Apache || Get Firefox || OpenOffice.org || Click || Slap ILMV || 1337 c0d || GotoMyPc For FREE! Part 1, Part 2

    | PHP Session --> Database Handler * Custom Error Handler * Installing PHP * HTML Form Handler * PHP 5 OOP * Using XML * Ajax * Xslt | VB6 Winsock - HTTP POST / GET * Winsock - HTTP File Upload

    Latest quote: crptcblade - VB6 executables can't be decompiled, only disassembled. And the disassembled code is even less useful than I am.

    Random VisualAd: Blog - Latest Post: When the Internet becomes Electricity!!


    Spread happiness and joy. Rate good posts.

  5. #5

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

    Re: If statement help:

    thanks visual, but it still isnt working

    Ive tried it these ways:

    PHP Code:
                    echo ($_POST['R/W']);
                echo(
    "\r\n"); 
    PHP Code:
                echo ($_POST['R/W']),echo("\r\n"); 
    and both times the page looks like this:
    r visitorcount.txt 916
    instead of
    r
    visitorcount.txt
    916

    any clues?

  6. #6
    VBA Nutter visualAd's Avatar
    Join Date
    Apr 2002
    Location
    Ickenham, UK
    Posts
    4,906

    Re: If statement help:

    Do you mean in the HTML? If so then you need to use "<br />" which created a line break.
    PHP || MySql || Apache || Get Firefox || OpenOffice.org || Click || Slap ILMV || 1337 c0d || GotoMyPc For FREE! Part 1, Part 2

    | PHP Session --> Database Handler * Custom Error Handler * Installing PHP * HTML Form Handler * PHP 5 OOP * Using XML * Ajax * Xslt | VB6 Winsock - HTTP POST / GET * Winsock - HTTP File Upload

    Latest quote: crptcblade - VB6 executables can't be decompiled, only disassembled. And the disassembled code is even less useful than I am.

    Random VisualAd: Blog - Latest Post: When the Internet becomes Electricity!!


    Spread happiness and joy. Rate good posts.

  7. #7
    Fanatic Member ALL's Avatar
    Join Date
    Jul 2004
    Location
    192.168.1.1
    Posts
    711

    Re: If statement help:

    when i am echo'ing a variable to find the value or check the value, i usually write it to a test file, like so:
    PHP Code:
    $handle fopen($filename'a'));
    fwrite($handle"$_POST['R/W']");
    fclose($handle); 
    the reason i usually use a file rather than echoing the variable is because a file is more reliable to get the info out of.
    Please support one of my projects?
    TKForums.com

    Web Forum
    JavaScript Wiki
    ________________________
    If somone helps you, please rate their post, by clicking the to rate their post

  8. #8

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

    Re: If statement help:

    does a mean for append? i think it does? so theres an r,w,a?

    and also, i mean that i when you echo at two different spots, they appear on one line, i hope the < br /> does it

  9. #9
    Fanatic Member ALL's Avatar
    Join Date
    Jul 2004
    Location
    192.168.1.1
    Posts
    711

    Re: If statement help:

    no, "a" is for "wrighting only, if the file does not exist, attempt to create it"

    look here for all the file handles:
    http://us4.php.net/manual/en/function.fopen.php
    Please support one of my projects?
    TKForums.com

    Web Forum
    JavaScript Wiki
    ________________________
    If somone helps you, please rate their post, by clicking the to rate their post

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