1. #1
    Stood in the Fire MmoFanatic's Avatar
    Join Date
    Nov 2010
    Location
    sweden
    Posts
    368

    Some php problems.

    <?php
    session_start();
    function loginForm(){
    echo'
    <div id="loginform">
    <form action="index.php" method="post">
    <p>Please enter your name to continue:</p>
    <label for="name">Name:</label>
    <input type="text" name="name" id="name" />
    <input type="submit" name="enter" id="enter" value="Enter" />
    </form>
    </div>
    ';
    }
    if(isset($_POST['enter'])){
    if($_POST['name'] != ""){
    $_SESSION['name'] = stripslashes(htmlspecialchars($_POST['name']));
    }
    else{
    echo '<span class="error">Please type in a name</span>';
    }
    }
    ?>



    so i'm trying to do this chat tutorial and it works just fine until i get to the bolded part where it just types it out on screen for some reason.
    so if there is anyone who know what are messing with my stuff could u please post.
    i'm having a real hard time figuering out why it's not working properly=/

    this is the site with the tutorial http://net.tutsplus.com/tutorials/ja...t-application/
    Last edited by MmoFanatic; 2012-11-03 at 01:36 PM.

  2. #2
    Pandaren Monk Prixie's Avatar
    Join Date
    Nov 2010
    Location
    Oostende, Belgium
    Posts
    1,994
    What exactly does it type out on the screen, the entire bolded part?
    Could you post a screenshot to show how it appears.

  3. #3
    Stood in the Fire MmoFanatic's Avatar
    Join Date
    Nov 2010
    Location
    sweden
    Posts
    368
    Quote Originally Posted by Amaris View Post
    What I might suggest is setting a variable before setting the session. So change this:

    for this


    Not sure if it'll work, but worth a try.




    Editing:

    Additionally, try just posting the form without it being inside a function. It should work fine. So completely outside the PHP tags, just have the form.
    still the same as before thanks anyways



    screen of how it looks right now
    Last edited by MmoFanatic; 2012-11-03 at 02:09 PM.

  4. #4
    Code:
    ';  
    }
    there's your problem... single quote, which is making the text come out.
    Kuroiwolf - 90 Brewmaster Monk
    Youtube Account Twitch TV
    Computer: Intel I7-3770k @ 4.5GHz | 16GB 1600MHz DDR3 RAM | AMD 7970 GHz @ 1200/1600 | ASUS Z77-V PRO Mobo|

  5. #5
    The single quote closes the echo opened at the start of the loginForm function.

    I ran this code through my own server and it worked fine. I'm inclined to say this is a server configuration issue. Have you ever had PHP script running on your local machine before?

    It may not be immediately obvious if you're new to programming or PHP, but it is also prining your login form code out on the screen. Since you eclosed this in a function and didn't call that function, that code would never be printed if the script was running correctly. It seems that PHP is throwing that out on the screen too and your browser is treating it as normal HTML and showing the form.

    For a better idea of what's going on, it might be worth copying the source of the page into a pastebin or something so we can see it?

  6. #6
    What happens if you get rid of the function? As currently you are not calling it anyway.

    Code:
    <?php
    session_start(); 
     
    echo' 
    <div id="loginform"> 
    <form action="index.php" method="post"> 
    <p>Please enter your name to continue:</p> 
    <label for="name">Name:</label> 
    <input type="text" name="name" id="name" /> 
    <input type="submit" name="enter" id="enter" value="Enter" /> 
    </form> 
    </div> 
    '; 
     
    if(isset($_POST['enter'])){ 
    if($_POST['name'] != ""){ 
    $_SESSION['name'] = stripslashes(htmlspecialchars($_POST['name'])); 
    } 
    else{ 
    echo '<span class="error">Please type in a name</span>'; 
    } 
    } 
    ?>
    Alternatively you could try it without the echo statement, and as clean HTML.

    Code:
    <?php
    session_start(); 
    ?>
      
    <div id="loginform"> 
    <form action="index.php" method="post"> 
    <p>Please enter your name to continue:</p> 
    <label for="name">Name:</label> 
    <input type="text" name="name" id="name" /> 
    <input type="submit" name="enter" id="enter" value="Enter" /> 
    </form> 
    </div> 
    
     <?php 
    if(isset($_POST['enter'])){ 
    if($_POST['name'] != ""){ 
    $_SESSION['name'] = stripslashes(htmlspecialchars($_POST['name'])); 
    } 
    else{ 
    echo '<span class="error">Please type in a name</span>'; 
    } 
    } 
    ?>
    Last edited by Cairhiin; 2012-11-03 at 03:58 PM.

  7. #7
    Stood in the Fire MmoFanatic's Avatar
    Join Date
    Nov 2010
    Location
    sweden
    Posts
    368
    Quote Originally Posted by Sporktacular View Post
    The single quote closes the echo opened at the start of the loginForm function.

    I ran this code through my own server and it worked fine. I'm inclined to say this is a server configuration issue. Have you ever had PHP script running on your local machine before?

    It may not be immediately obvious if you're new to programming or PHP, but it is also prining your login form code out on the screen. Since you eclosed this in a function and didn't call that function, that code would never be printed if the script was running correctly. It seems that PHP is throwing that out on the screen too and your browser is treating it as normal HTML and showing the form.

    For a better idea of what's going on, it might be worth copying the source of the page into a pastebin or something so we can see it?
    yep that was the problem had wrong config working fine now thanks m8
    and thanks to all of you who tried to help me=)

  8. #8
    Quote Originally Posted by Sporktacular View Post
    The single quote closes the echo opened at the start of the loginForm function.
    Ah.. it's just horribly laid out...

    Might as well drop out of php for the html elements, like Cair suggested.
    Kuroiwolf - 90 Brewmaster Monk
    Youtube Account Twitch TV
    Computer: Intel I7-3770k @ 4.5GHz | 16GB 1600MHz DDR3 RAM | AMD 7970 GHz @ 1200/1600 | ASUS Z77-V PRO Mobo|

Posting Permissions

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