...

View Full Version : form submiting to it's self. if statement not working



[m]
09-21-2003, 05:12 AM
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 :thumbsup:


<?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

Acecool
09-21-2003, 05:17 AM
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 :thumbsup:


<?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

[m]
09-21-2003, 05:20 AM
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 :rolleyes:

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

thanx

Nightfire
09-21-2003, 04:09 PM
You can't have 2 form fields with the same name

this'll work



<?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>

[m]
09-22-2003, 06:08 AM
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

cv98
09-25-2003, 01:40 AM
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!

[m]
10-14-2003, 11:58 PM
ah I will have to change the .ini (it would make my life alot easier)

michael.hd
10-15-2003, 12:24 AM
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.

[m]
10-15-2003, 02:54 AM
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.

cv98
10-16-2003, 12:44 AM
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.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum