Help - Search - Members - Calendar
Full Version: Submit Button
Zymic Webmaster Forums > Web Design & Development > Server Side Scripting > PHP
footballfan
I have a Submit button on my login page which has " print "<form action=$PHP_SELF METHOD=POST>";" and a submit button "print "<tr><td colspan=\"2\"><font face=\"Arial\" color=\"Black\" size=4><center><input type=submit value='Login'></center></font></td></tr>"".

I have a logic of 'stages', where (empty($stage)) causes the login text boxes to appear, and when $stage=="2" ($stage==2 triggered by a hidden value after the 'Login' button is clicked) it either should redirect or it would say password/username wrong if appropriate.

HOWEVER,

Every time I click on the 'Login' submit button, it says Error 404 page not found, regardless whether the password is correct or not. On my Apache server it does not happen. It seems that ($stage==2) is not going through.

Any ideas why?

Thanks.

Ed
You don't actually need '$PHP_SELF' to post to itself you can use:

CODE
action=""


The reason your code doesn't work though is because it appears you are relying on registered globals, take this field for example:

CODE
<input type="hidden" name="somevar" value="foobar" />


If you used :

CODE
var_dump($somevar);


It would output 'NULL'; however if you used:

CODE
var_dump($_POST['somevar']);


Now that (assuming the form method is set to POST) would output:

CODE
string(6) "foobar"


See, your value is now there.

So in short, replace any form variables with their superglobal counter parts, if you still want a PHP_SELF, you can use:

CODE
$_SERVER['PHP_SELF']


http://www.php.net/reserved.variables
footballfan
I tried all of the above, and unfortunately it did not work. Is there any reason why this works on my apache server at home and not here?

I even tried just sending the 'stage' as $POST_['stage'] and it did not work. wacko.gif
footballfan
Also, even if stage=2 isn't going through, why is there an Error 404 page?
MrTouz
isnt 404 due to document not found ?

i guess you probably sending info to a unknow place... but sometimes with some PHP codes i get this 404 error even tho it has nothing to do with a not found document.... just a syntax error or a bad calling mistake... well sorry can't help... i am still a newbie at PHP :/
Ed
QUOTE(MrTouz @ Nov 1 2007, 12:20 PM) *
isnt 404 due to document not found ?

i guess you probably sending info to a unknow place... but sometimes with some PHP codes i get this 404 error even tho it has nothing to do with a not found document.... just a syntax error or a bad calling mistake... well sorry can't help... i am still a newbie at PHP :/


Yes, although in his example the form action was supplied with '$PHP_SELF', which if register globals is off, does not contain a value. Probably best to see the interpretted html to gauge what is now wrong.
footballfan
OK, it's sorted. Registered globals... sorted biggrin.gif

Problem #2

when I have a variable in my addresss, like test.php?stage=2, how it's still displaying stuff when stage should be empty? the link is a link to itself so my syntax is
CODE
print "<tr><td width=15%><font size=3 face=\"Arno Pro Smbd\">$row2[dispname]</td><td width=904><font size=3 face=\"Arno Pro Smbd\"><a href=\"{$_SERVER['PHP_SELF']}?$_POST['stage']=2&$_POST['id']=$row[topicid]\">$row[Title]</a></td></tr>";


Where 'id' is another variable on my page.

Thanks
Ed
Not sure I follow your question.

You sure you don't mean:

CODE
stage=$_POST['stage']


It's also much better to escape php for outputting HTML, so not using 'print / echo' apart from outputting the variables in your HTML.

example:

CODE
<b><?php echo $myvariable; ?></b>
This is a "lo-fi" version of our main content. To view the full version with more information, formatting and images, please click here.
Invision Power Board © 2001-2012 Invision Power Services, Inc.