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.
Results 1 to 10 of 10
  1. #1
    [m]
    [m] is offline
    New Coder
    Join Date
    Nov 2002
    Location
    Virginia, USA
    Posts
    52
    Thanks
    0
    Thanked 0 Times in 0 Posts

    form submiting to it's self. if statement not working

    the title basicly explains it all. I am making my first script like this, one that submits to its self, but I'm having trouble. it isn't recognizing the beensubmitted. what is wrong with it. I have spent a while on it and I can't figure it out. I really wanna get this right ...I think it would be very usefull
    PHP Code:
    <?php
    if ($beensubmitted){
        print (
    " success!<br>\n");

        }else{
            print (
    "no go... try agian when you fix it");
        

    }
    ?>
    <form action="create.php" method=post>
                hit submit to see if it works
                <input type=hidden name=beensubmitted value=TRUE>
                <input type=submit value="login">

    </form>
    oh BTW the I saved the file as create.php
    Last edited by [m]; 09-21-2003 at 06:14 AM.
    .:mike:.

    I'm a newbie

  • #2
    New Coder
    Join Date
    Sep 2003
    Posts
    98
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: form submiting to it's self. if statement not working

    Originally posted by [m]
    the title basicly explains it all. I am making my first script like this, one that submits to its self, but I'm having trouble. it isn't recognizing the beensubmitted. what is wrong with it. I have spent a while on it and I can't figure it out. I really wanna get this right ...I think it would be very usefull
    PHP Code:
    <?php
    if ($beensubmitted) {
        print (
    " success!<br>\n");
    }
    ?>
    <form action="create.php" method=post>
                hit submit to see if it works
                <input type=hidden name=beensubmitted value=TRUE>
                <input type=submit value="login" name="beensubmitted">

    </form>
    oh BTW the I saved the file as create.php

    You dont want the else, or it will show if the form wasnt submitted...

    also you forgot to give the submit button the name beensubmitted

    default submit name is submit or $submit

  • #3
    [m]
    [m] is offline
    New Coder
    Join Date
    Nov 2002
    Location
    Virginia, USA
    Posts
    52
    Thanks
    0
    Thanked 0 Times in 0 Posts
    ok I felt I had to make a new post for this:

    http://members.lycos.co.uk/mike77800/create.php

    that works but the same script when used in phpdev on my computer doesn't work.....what could be causing that?

    I spent over an hour trying to get that to work but come to find out it I was WAAAAAY off

    *EDIT* wow acecool fast responce thanx. well eathir way would have worked but I like your way alot better...more logical

    thanx
    Last edited by [m]; 09-21-2003 at 06:24 AM.
    .:mike:.

    I'm a newbie

  • #4
    Senior Coder Nightfire's Avatar
    Join Date
    Jun 2002
    Posts
    4,265
    Thanks
    6
    Thanked 48 Times in 48 Posts
    You can't have 2 form fields with the same name

    this'll work

    PHP Code:
    <?php
    if ($_POST['submit']) {
        print (
    " success!<br>\n");
    }
    ?>
    <form action="create.php" method=post>
                hit submit to see if it works
                <input type=hidden name=beensubmitted value=TRUE>
                <input type=submit value="login" name="submit">

    </form>

  • #5
    [m]
    [m] is offline
    New Coder
    Join Date
    Nov 2002
    Location
    Virginia, USA
    Posts
    52
    Thanks
    0
    Thanked 0 Times in 0 Posts
    ok thanx nighfire that is what I'm lookin for. for some reasion it wasn't submiting to it's self. but with that $_POST['submit'] it is working just like it should
    .:mike:.

    I'm a newbie

  • #6
    New to the CF scene
    Join Date
    Sep 2003
    Posts
    7
    Thanks
    0
    Thanked 0 Times in 0 Posts
    The reason it was only working once you used the superglobals ($_POST) method on your install is because you probably have PHP > 4.1 and by default in php.ini register_globals is set to off. if you want to write your scripts without using the superglobals, there are two ways you can do it:
    1 - edit your php.ini file and set register_globals to on.
    2 - you can put the following code at the top of your scripts and your problems will be fixed.
    <?php if ( phpversion() >="4.2.0") extract($_POST); ?>

    Hope this helps!

  • #7
    [m]
    [m] is offline
    New Coder
    Join Date
    Nov 2002
    Location
    Virginia, USA
    Posts
    52
    Thanks
    0
    Thanked 0 Times in 0 Posts
    ah I will have to change the .ini (it would make my life alot easier)
    .:mike:.

    I'm a newbie

  • #8
    New Coder
    Join Date
    May 2003
    Location
    UK
    Posts
    68
    Thanks
    0
    Thanked 0 Times in 0 Posts
    thanks cv98 for the code snippet. I will try it out. I have some old code that needs globals on.

    Hi [m],

    I think you shouldn't bother with changing the ini file. Globals off is the way to go and will get more common in the future.

    On most of my newer pages i make a function that collects all the data form the previous submit and puts it in an array. While it does this it checks that the data is ok (text is text, numerics are numerics etc) stops people busting my sites.

    If you do this at the top of the page you know that all the data from the previous page is ok / safe / present. Your code becomes much easier to modify later.
    They only tell you its a stupid question when they don't know the answer!

  • #9
    [m]
    [m] is offline
    New Coder
    Join Date
    Nov 2002
    Location
    Virginia, USA
    Posts
    52
    Thanks
    0
    Thanked 0 Times in 0 Posts
    I guess I can't go wrong with useing the $_POST[] thing so I will use that from now on to prevent future bugs

    but when it comes to useing other peoples scripts I have decided to change the ini file. I have come across so many annoying bugs becuse they assume that I have set register_globals to on. well that is my complaint and solution.
    .:mike:.

    I'm a newbie

  • #10
    New to the CF scene
    Join Date
    Sep 2003
    Posts
    7
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Instead of changing your ini file, dump the code snippet above (if using post method) into an include file and include it in any page that assumes register_globals on.
    Or, if your not sure where your vars are coming from, use the snippet below, also in an include.

    <?
    if ( phpversion() >= "4.2.0")
    {
    extract($_POST);
    extract($_GET);
    extract($_SERVER);
    extract($_ENV);
    extract($_COOKIE);
    }
    ?>

    If you change your ini file, and are developing with register_globals on, you might have errors that won't be picked up, because register_globals will still pick up your vars.


  •  

    Posting Permissions

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