Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Page 1 of 2 12 LastLast
Results 1 to 15 of 16
  1. #1
    New Coder
    Join Date
    Jul 2006
    Posts
    13
    Thanks
    0
    Thanked 0 Times in 0 Posts

    php post to self thing dosn't work at all.

    okay, listen up, I'm having problems with my PHP_SELF code, its not working.
    It won't post. The only thing that It would does is, well erase everything I
    entered (just like what the reset button would do)

    anyways, here is my code

    this is the beginning: (I know I'm supposed to have hte error thing)
    PHP Code:
    <?php
    $first 
    $_POST["first"];
    $last $_POST["last"];
    $instro $_POST["instro"];
    $like $_POST["like"];
    $music $_POST["music"];
    $tellme $_POST["tellme"];
    if (!isset(
    $_POST['submit'])) {
    ?>
    <html> ...
    this is the code in the form tag:

    PHP Code:
    <form method="post" action="<?php echo $PHP_SELF;?>">
    and this is the output code, telling it how it should display once its done:

    PHP Code:
        </form>
    <?php
    } else {
    echo 
    "first: "$first "<p>";
    echo 
    "</p>last: " $last "<p>";
    echo 
    "</p>email: " $email "<p>";
    echo 
    "</p>instro: " $instro "<p>";
    echo 
    "</p>likes: " $like "<p>";
    echo 
    "</p>types of music: ";
    foreach (
    $music as $k => $v)
    {
        echo 
    $v;
            if (
    $k != count($music) - 1)
                echo 
    ", ";
        }
    echo 
    "<p>";
    echo 
    "</p>more info:<p>".$tellme."</p>";
    }
    ?>
    </body>
    </html>
    I've been dealing wiht this problem for days, I don't understand why it dosn't
    work! I've looked though hundreds of tutorials, and I can't find an awnser.

  • #2
    Super Moderator Inigoesdr's Avatar
    Join Date
    Mar 2007
    Location
    Florida, USA
    Posts
    3,638
    Thanks
    2
    Thanked 404 Times in 396 Posts
    $_server['php_self'];

  • #3
    New Coder
    Join Date
    Jul 2006
    Posts
    13
    Thanks
    0
    Thanked 0 Times in 0 Posts
    thks!

  • #4
    Senior Coder CFMaBiSmAd's Avatar
    Join Date
    Oct 2006
    Location
    Denver, Colorado USA
    Posts
    2,960
    Thanks
    2
    Thanked 304 Times in 296 Posts
    Both the variable name and the constant value in that are going to be case sensitive -

    $_SERVER['PHP_SELF'];
    If you are learning PHP, developing PHP code, or debugging PHP code, do yourself a favor and check your web server log for errors and/or turn on full PHP error reporting in php.ini or in a .htaccess file to get PHP to help you.

  • #5
    Regular Coder the-dream's Avatar
    Join Date
    Mar 2007
    Location
    Northamptonshire, UK
    Posts
    477
    Thanks
    8
    Thanked 4 Times in 4 Posts
    Y can also just post it to the same file. Like instead of saying server self and you are working in ' form.php ' just set the action to form.php.

  • #6
    Regular Coder the-dream's Avatar
    Join Date
    Mar 2007
    Location
    Northamptonshire, UK
    Posts
    477
    Thanks
    8
    Thanked 4 Times in 4 Posts
    Oh!
    And welcome to Coding Forums!

  • #7
    Senior Coder
    Join Date
    Jan 2007
    Posts
    1,648
    Thanks
    1
    Thanked 58 Times in 54 Posts
    Y can also just post it to the same file. Like instead of saying server self and you are working in ' form.php ' just set the action to form.php.
    This way you could rename the file and not have to worry about it breaking.

  • #8
    Regular Coder
    Join Date
    Jun 2004
    Posts
    130
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by the-dream View Post
    Y can also just post it to the same file. Like instead of saying server self and you are working in ' form.php ' just set the action to form.php.
    i guess that´s about as smart as using absolute paths

  • #9
    New Coder
    Join Date
    Jul 2006
    Posts
    13
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by the-dream View Post
    Y can also just post it to the same file. Like instead of saying server self and you are working in ' form.php ' just set the action to form.php.
    oh, sweet.

    so, whats the better way?

  • #10
    Senior Coder CFMaBiSmAd's Avatar
    Join Date
    Oct 2006
    Location
    Denver, Colorado USA
    Posts
    2,960
    Thanks
    2
    Thanked 304 Times in 296 Posts
    Use the method that you are (with the proper variable name) -
    PHP Code:
    <form method="post" action="<?php echo $_SERVER['PHP_SELF'];?>">
    This is independent of the file name that it is contain in and can be reused in other code without the need to remember to edit the action="..." parameter (I have seen more than a few posts where someone stated their form processing code was not working... when in fact it was sending the data to the wrong or non-existent action="..." file.)

    Just for the record, the original variable that you had, $PHP_SELF, only works when register_globals are on.
    If you are learning PHP, developing PHP code, or debugging PHP code, do yourself a favor and check your web server log for errors and/or turn on full PHP error reporting in php.ini or in a .htaccess file to get PHP to help you.

  • #11
    New to the CF scene
    Join Date
    Mar 2007
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts
    $_SERVER[ 'SCRIPT_NAME' ] is the preferred variable to use for this application -- $_SERVER['PHP_SELF'] is based on user input and vulnerable to cross site scripting attacks.

    You probably won't encounter these sorts of issues until you build larger apps that start caching pages and the like, but it's good to get in the habit now. It's not fun to be looking at a production application you wrote that someone has inserted a bunch of XSS attacks into.

    See here for more information:

    http://blog.phpdoc.info/archives/13-guid.html

  • #12
    Super Moderator Inigoesdr's Avatar
    Join Date
    Mar 2007
    Location
    Florida, USA
    Posts
    3,638
    Thanks
    2
    Thanked 404 Times in 396 Posts
    Quote Originally Posted by CFMaBiSmAd View Post
    Both the variable name and the constant value in that are going to be case sensitive -

    $_SERVER['PHP_SELF'];
    That's odd.. I typed them in caps when I posted it.

  • #13
    Senior Coder Nightfire's Avatar
    Join Date
    Jun 2002
    Posts
    4,266
    Thanks
    6
    Thanked 48 Times in 48 Posts
    The forum has the 'anti-shout' setting on. If a post contains all uppercase letters, they'll be converted to lowercase

  • #14
    Super Moderator Inigoesdr's Avatar
    Join Date
    Mar 2007
    Location
    Florida, USA
    Posts
    3,638
    Thanks
    2
    Thanked 404 Times in 396 Posts
    Quote Originally Posted by Nightfire View Post
    The forum has the 'anti-shout' setting on. If a post contains all uppercase letters, they'll be converted to lowercase
    Ah, thanks for letting me know.

  • #15
    Senior Coder
    Join Date
    Mar 2003
    Location
    Atlanta
    Posts
    1,037
    Thanks
    14
    Thanked 30 Times in 28 Posts
    Quote Originally Posted by rajbot View Post
    $_SERVER[ 'SCRIPT_NAME' ] is the preferred variable to use for this application -- $_SERVER['PHP_SELF'] is based on user input and vulnerable to cross site scripting attacks.

    You probably won't encounter these sorts of issues until you build larger apps that start caching pages and the like, but it's good to get in the habit now. It's not fun to be looking at a production application you wrote that someone has inserted a bunch of XSS attacks into.

    See here for more information:

    http://blog.phpdoc.info/archives/13-guid.html
    What about when you add striptags?

    PHP Code:
    strip_tags$_SERVER['PHP_SELF'] ); 
    $_SERVER[ 'SCRIPT_NAME' ]
    Guess I'll look into using $_SERVER[ 'SCRIPT_NAME' ] as an alternative.
    Most of my questions/posts are fairly straightforward and simple. I post long verbose messages in an attempt to be thorough.


  •  
    Page 1 of 2 12 LastLast

    Posting Permissions

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