www.webdeveloper.com
Results 1 to 4 of 4

Thread: PHP not working :(

  1. #1
    Join Date
    Jun 2013
    Posts
    1

    PHP not working :(

    I'm new, to the forum and to PHP in general, and I would appreciate some help with this! It's probably a simple mistake! Here's the code, I need the 'loginForm' to show first, then once a name has been entered, it to view the rest of the body, here it is! (css and jquery works fine )

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <title>Chat - Customer Module</title>
    <link type="text/css" rel="stylesheet" href="style.css" />
    </head>
    <?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>';
    }
    }
    ?>

    <?php


    if(!isset($_SESSION['name'])){
    loginForm();
    }
    else{
    ?>

    <div id="wrapper">
    <div id="menu">
    <p class="welcome">Welcome, <b></b></p>
    <p class="logout"><a id="exit" href="#">Exit Chat</a></p>
    <div style="clear:both"></div>
    </div>

    <div id="chatbox"></div>

    <form name="message" action="">
    <input name="usermsg" type="text" id="usermsg" size="63" />
    <input name="submitmsg" type="submit" id="submitmsg" value="Send" />
    </form>
    </div>
    <script type="text/javascript" src="jQuery.js"></script>
    <script type="text/javascript">
    // jQuery Document
    $(document).ready(function(){

    });
    </script>
    <?php
    }
    ?>
    </body>
    </html>

  2. #2
    Join Date
    May 2013
    Posts
    119
    I think its problem with else statement missing firs check this statement. i hope you will be get solution.

  3. #3
    Join Date
    Mar 2012
    Posts
    1,413
    I haven't checked your code in detail, but I suspect there is a fundamental misunderstanding of how php works:

    a) Php does not run in the browser. You have to run it on a web server.

    b) Php will not output a web page to the client browser until it completes its processing on the server. It is not interactive like javascript.

  4. #4
    Join Date
    Aug 2012
    Location
    TX
    Posts
    293
    This might sound ridiculous but make sure your file extension is .php and not .html

    cause it seems to work fine for me when i loaded it to my environment.

    once i type my name in i get the chat box allowing me to post a message. the exit link is not destroying the session. you need to add

    <?php
    session_destroy();
    ?>

    or something to terminate the session allowing you to return to enter name when someone clicks exit.
    Last edited by Nicholas Diaz; 06-13-2013 at 04:43 PM.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

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



Recent Articles