Whats wrong with this code?

Discussion in 'PHP' started by Loget, Jun 2, 2009.

  1. #1
    <html>
    <body>
    <div style="background-color:green;width:200px;">
    
    <b>Config Grabber BETA</b>
      <form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post">
        Are you ready?: <input name="go" size="0">
        <input type="submit" name="submit" value="Go">
        </form>
        <?php
    $rook = $_POST['go'];
    if ($rook > 0);
    {
    	
    
    $file = includes/config.php;
    $result = file_get_contents($file);
    }
    echo "$result";
    else {
    	echo "Something went wrong....";
    }
    ?>
    </div>
    </body>
    </html>
    Code (markup):
    I just want it to get the file and echo its contents :confused:
     
    Loget, Jun 2, 2009 IP
  2. Liam_Tatton

    Liam_Tatton Peon

    Messages:
    4
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #2
    Do you get any errors when you run the code?
     
    Liam_Tatton, Jun 2, 2009 IP
  3. Loget

    Loget Peon

    Messages:
    126
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3
    I just get a blank page.
     
    Loget, Jun 2, 2009 IP
  4. Fr0Gs

    Fr0Gs Peon

    Messages:
    42
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #4
    if ($rook > 0); there shouldent be a ; after that
     
    Fr0Gs, Jun 2, 2009 IP
  5. KalvinB

    KalvinB Peon

    Messages:
    2,787
    Likes Received:
    78
    Best Answers:
    0
    Trophy Points:
    0
    #5
    
    $rook = isset($_POST['go']) ? 1 : 0;
    
    Code (markup):
    The form element "go" is never given a value so the value of $_POST['go'] will be an empty string which in PHP land is equal to 0.

    
    <input name="go" size="0" value="1">
    
    Code (markup):
    Will also work.
     
    KalvinB, Jun 2, 2009 IP
  6. ezprint2008

    ezprint2008 Well-Known Member

    Messages:
    611
    Likes Received:
    15
    Best Answers:
    2
    Trophy Points:
    140
    Digital Goods:
    1
    #6
    a lot of that code is wrong.
    Weak HTML form code, weak PHP code ..
    youre basically trying to put together a script and you dont know HTML forms or PHP that well .. keep learning.

    the two posts above are right. you have no value in your "name" field
    <input type="text" name="go" value="1234">


    theres no ; after the rook variable where you should have a

    and your includes/config.php
    include('config.php');

    keep learning.
     
    ezprint2008, Jun 2, 2009 IP
  7. kishore415

    kishore415 Well-Known Member

    Messages:
    1,462
    Likes Received:
    41
    Best Answers:
    0
    Trophy Points:
    160
    #7
    this is correct as you said..

    His intension is not to include files..but read the file from includes folder..what he has written is correct

    and you echo "$result";

    should go inside if loop ...it shoould not be outisde of if loop before "else" statement...

    All the best..dont hesitate to more questions...
     
    kishore415, Jun 2, 2009 IP
  8. Spawny

    Spawny Well-Known Member

    Messages:
    252
    Likes Received:
    23
    Best Answers:
    0
    Trophy Points:
    110
    #8
    you should echo the result variable ' $result ' inside the if statement
     
    Spawny, Jun 3, 2009 IP
  9. Loget

    Loget Peon

    Messages:
    126
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #9
    <html>
    <body>
    <div style="background-color:green;width:200px;">
    
    <b>Config Grabber BETA</b>
      <form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post">
        Are you ready?: <input name="go" size="0" value="1"">
        <input type="submit" name="submit" value="Go">
        </form>
        <?php
    $rook = isset($_POST['go']) ? 1 : 0;
    if ($rook > 0)
    {
    	
    
    $file = includes/config.php;
    $result = file_get_contents($file);
    echo $result;
    
    }
    
    else {
    	echo "Something went wrong....";
    }
    ?>
    </div>
    </body>
    </html>
    PHP:
    Is that alright?
     
    Loget, Jun 5, 2009 IP