Go Back   CodingForums.com > :: Server side development > PHP

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 09-21-2003, 05:12 AM   PM User | #1
[m]
New Coder

 
Join Date: Nov 2002
Location: Virginia, USA
Posts: 52
Thanks: 0
Thanked 0 Times in 0 Posts
[m] is an unknown quantity at this point
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
__________________
.:mike:.

I'm a newbie

Last edited by [m]; 09-21-2003 at 05:14 AM..
[m] is offline   Reply With Quote
Old 09-21-2003, 05:17 AM   PM User | #2
Acecool
New Coder

 
Join Date: Sep 2003
Posts: 98
Thanks: 0
Thanked 0 Times in 0 Posts
Acecool is an unknown quantity at this point
Re: form submiting to it's self. if statement not working

Quote:
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
__________________
http://www.acecoolco.com/avs/Acecool..._Signature.php
If you plan on contacting me, please read this: Legal Terms & Conditions
Acecool is offline   Reply With Quote
Old 09-21-2003, 05:20 AM   PM User | #3
[m]
New Coder

 
Join Date: Nov 2002
Location: Virginia, USA
Posts: 52
Thanks: 0
Thanked 0 Times in 0 Posts
[m] is an unknown quantity at this point
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
__________________
.:mike:.

I'm a newbie

Last edited by [m]; 09-21-2003 at 05:24 AM..
[m] is offline   Reply With Quote
Old 09-21-2003, 04:09 PM   PM User | #4
Nightfire
Senior Coder

 
Nightfire's Avatar
 
Join Date: Jun 2002
Posts: 4,266
Thanks: 6
Thanked 48 Times in 48 Posts
Nightfire is on a distinguished road
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>
__________________
Blue Panda
Website Design | 1 Pound Ads | 'ow much? | Coding Geeks
Nightfire is offline   Reply With Quote
Old 09-22-2003, 06:08 AM   PM User | #5
[m]
New Coder

 
Join Date: Nov 2002
Location: Virginia, USA
Posts: 52
Thanks: 0
Thanked 0 Times in 0 Posts
[m] is an unknown quantity at this point
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
[m] is offline   Reply With Quote
Old 09-25-2003, 01:40 AM   PM User | #6
cv98
New to the CF scene

 
Join Date: Sep 2003
Posts: 7
Thanks: 0
Thanked 0 Times in 0 Posts
cv98 is an unknown quantity at this point
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!
cv98 is offline   Reply With Quote
Old 10-14-2003, 11:58 PM   PM User | #7
[m]
New Coder

 
Join Date: Nov 2002
Location: Virginia, USA
Posts: 52
Thanks: 0
Thanked 0 Times in 0 Posts
[m] is an unknown quantity at this point
ah I will have to change the .ini (it would make my life alot easier)
__________________
.:mike:.

I'm a newbie
[m] is offline   Reply With Quote
Old 10-15-2003, 12:24 AM   PM User | #8
michael.hd
New Coder

 
Join Date: May 2003
Location: UK
Posts: 68
Thanks: 0
Thanked 0 Times in 0 Posts
michael.hd is an unknown quantity at this point
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!
michael.hd is offline   Reply With Quote
Old 10-15-2003, 02:54 AM   PM User | #9
[m]
New Coder

 
Join Date: Nov 2002
Location: Virginia, USA
Posts: 52
Thanks: 0
Thanked 0 Times in 0 Posts
[m] is an unknown quantity at this point
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
[m] is offline   Reply With Quote
Old 10-16-2003, 12:44 AM   PM User | #10
cv98
New to the CF scene

 
Join Date: Sep 2003
Posts: 7
Thanks: 0
Thanked 0 Times in 0 Posts
cv98 is an unknown quantity at this point
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.
cv98 is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 07:36 PM.


Advertisement
Log in to turn off these ads.