SitePoint Sponsor

User Tag List

Results 1 to 6 of 6
  1. #1
    Knowledge is key 2 progression Tryst's Avatar
    Join Date
    Sep 2003
    Location
    Wales
    Posts
    1,181
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Form not posting to itself through PHP_SELF

    Hi all,

    I have a bit of code that is begin to piss me off. I want the form to post to itself, but it doesn't seem to be doing it for some reason or another. I've used identical code in previous projects, but yet doesn't work in this current project :s

    The code is that is causing the probelm is listed below..

    PHP Code:
    <?php
    session_start
    ();
    if (isset(
    $_SESSION["test"])){
    echo 
    $_SESSION["test"];
    }
    else {
    echo 
    "new session";
    $_SESSION["test"]="session variable saved";
    }
    ?>

    <?php echo "<?xml version=\"1.0\" encoding=\"iso-8859-1\"?".">"?>
    <!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>Admin Section - Churchill's Art and Stationary, artstuff.co.uk</title>
    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />

    <style type="text/css" media="screen"><!--
    <!-- style definitions here -->
    </style>
    </head>
    <body>
        <div id="horizon">
            <div id="content">
                <div class="headline">Churchill's Admin</div>
                <div class="logintext">Please log in...</div>
                <div class="logintext">Username:</div>
                <form method="post" action="<?  echo $_SERVER['PHP_SELF'?>">
                <div class="formDisplay"><input type="text" id="user" tabindex="1" /></div>
                <div class="logintext">Password:</div>
                <div class="formDisplay"><input type="text" id="pass" tabindex="2" /></div>
                <div class="formDisplay"><input type="submit" value="Log in" /></div>
                </form>
            </div>
        </div>
    </body>
    </html>
    Hope someone can see the problem.

    Cheers

    Tryst

  2. #2
    SitePoint Zealot
    Join Date
    Jan 2004
    Location
    vta,ca,usa
    Posts
    180
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    First thing I see wrong with it is the missing semicolon at the end of your statement
    PHP Code:
    <?  echo $_SERVER['PHP_SELF'?>
    Secondly, even if it did work as is, you don't actually have any code to handle the form data. What did you expect to happen?

    [edit]
    You also don't define a name for a form variable, you're simply using an id to handle the values.
    Code:
    <input type="text" name="user" id="user">

  3. #3
    Knowledge is key 2 progression Tryst's Avatar
    Join Date
    Sep 2003
    Location
    Wales
    Posts
    1,181
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Ok, the semicolon has now been in it, but it didn't solve it. I did have it in previously, but must have missed it when posting it here.

    The code to handle the data will be put in later, firstly I want to see that the form is actually posting to itself. I have the session testing code at the top and nothing is even being printed through that.

    Cheers

    Tryst

  4. #4
    SitePoint Zealot
    Join Date
    Jan 2004
    Location
    vta,ca,usa
    Posts
    180
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I have the session testing code at the top and nothing is even being printed through that.
    Ok, obviously you have some sort of problem with your session config, as the script works fine on my server.

    Can you post your session settings?

    You can change your script slightly and put a counter in that will verify the script is changing (when it works, that is)
    PHP Code:
    <?php
    session_start
    ();
    if (isset(
    $_SESSION["test"]) && isset($_SESSION['count'])){
      echo 
    $_SESSION["test"] .'<br />';
      
    $_SESSION['count']++;
      echo 
    $_SESSION['count'];
    } else {
      echo 
    "new session";
      
    $_SESSION["test"]="session variable saved";
      
    $_SESSION['count'] = 0;
    }
    ?>

  5. #5
    Knowledge is key 2 progression Tryst's Avatar
    Join Date
    Sep 2003
    Location
    Wales
    Posts
    1,181
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I don't think it is the session settings that are problematic as I have sessions working properly across other scripts.

    When I use the form to post to another script, it works, but it doesn't seem to post to itself. I've even inserted some code to test whether the form values are being passed to it, but they aren't.

    I am pretty sure that the problem lies within the $php_self side of things

    When I print $_SERVER['php_self'] to the screen, I get /churchills/admin.php. Which is the right location.

    Even when I put the 'action' attribute value to admin.php (the name its page) it still doesn't call itself.

    Tryst

  6. #6
    Knowledge is key 2 progression Tryst's Avatar
    Join Date
    Sep 2003
    Location
    Wales
    Posts
    1,181
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I've solved the problem!!

    It is related to the CSS elements I had inserted on the page.

    Because I was using div elements to centre my content, the code I was using to/test variables and print at the top of the screen was actually being written off screen somewhere. Strange cause the browser window didn't provide any scroll bars to view it.

    Anyway, problem solved. (and it was a bugger to find)

    Cheers guys

    Tryst


Bookmarks

Posting Permissions

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