This is a discussion on Forms, post and register_globals within the PHP Language forums, part of the PHP Programming Forums category; I have a simple form which I want to try out (before rewriting to do something useful)... and am having ...
|
|||||||
| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
|
|||
|
I have a simple form which I want to try out (before rewriting to do
something useful)... and am having problems getting the variable to output. From what I read I have coded it to get around the "register_globals" being off (both on my localhost and my ISP)... but I cannot get the variable output, below is my HTML and PHP. Basically, the HTML file contains a form with a select box which is supposed to pass the variable to the PHP script so it can print the result of the variable selected. After much searching online and head scratching, I can't find what I've done wrong. Can anyone help? Dariusz ++HTML++ <HTML><HEAD><TITLE>Redirector test</TITLE></HEAD> <BODY> <FORM method="POST" action="redirector.php"> <select name="$_POST['album']"> <option value="a01-t01" SELECTED>Album 01, Track 01</option> <option value="a01-t02">Album 01, Track 02</option> </select> <input type="submit" value="Submit"> </FORM> </BODY> </HTML> ++PHP++ <? echo ('The results is: $album'); ?> |
|
|||
|
Dariusz wrote:
> I have a simple form which I want to try out (before rewriting to do > something useful)... and am having problems getting the variable to output. > From what I read I have coded it to get around the "register_globals" > being off (both on my localhost and my ISP)... but I cannot get the > variable output, below is my HTML and PHP. You've got them backwards... > ++HTML++ > <select name="$_POST['album']"> <select name="album"> > ++PHP++ > echo ('The results is: $album'); echo 'The results is: ',$_POST['album']; -- Justin Koivisto - spam@koivi.com PHP POSTERS: Please use comp.lang.php for PHP related questions, alt.php* groups are not recommended. |
|
|||
|
ng@lycaus.plusYOURSHIT.com (Dariusz) schrieb:
> ++HTML++ > > <FORM method="POST" action="redirector.php"> > <select name="$_POST['album']"> > <option value="a01-t01" SELECTED>Album 01, Track 01</option> > <option value="a01-t02">Album 01, Track 02</option> > </select> > <input type="submit" value="Submit"> > </FORM> <form method='post' action='redirector.php' name='myform'> <select name='album'> <option value='a01-t01' selected='selected'> Album 01, Track 01</option> <option value='a01-t02'> Album 01, Track 02</option> </select> <input type='submit' name='submit' value='Submit'> </form> > ++PHP++ > > <? > echo ('The results is: $album'); > ?> <? echo ("The result is {$_POST['album']}"); ?> or better <?php if (isset($_POST['album'])) { echo ('The result is: ' . $_POST['album']); } ?> Compare your code and my code and try to find out what you've done wrong. If you really can't figure it out and need more explanations feel free to ask again. Regards, Matthias |
|
|||
|
In article <jvswb.1193$Uz.37639@news7.onvoy.net>, Justin Koivisto <spam@koivi.com> wrote:
>You've got them backwards... > >> ++HTML++ >> <select name="$_POST['album']"> > ><select name="album"> > >> ++PHP++ >> echo ('The results is: $album'); > >echo 'The results is: ',$_POST['album']; > Thanks for that... I thought it must be something simple as there was not much code there to get wrong !! Dariusz |
|
|||
|
In article <bpto91.1fg.1@usenet.esken.de>, Matthias Esken <netzkontrolle-nospam@usenetverwaltung.org> wrote:
>ng@lycaus.plusYOURSHIT.com (Dariusz) schrieb: Okay the HTML you you corrected I redid... >> ++PHP++ ><? >echo ("The result is {$_POST['album']}"); >?> Now with the correct PHP code, the thing works. Thanks for that :-). >or better > ><?php >if (isset($_POST['album'])) { > echo ('The result is: ' . $_POST['album']); > } >?> > >Compare your code and my code and try to find out what you've done >wrong. If you really can't figure it out and need more explanations feel >free to ask again. Well, as you bring it up, what is the difference between the first PHP code and the second? Which is better to use? Why? etc... Dariusz |
|
|||
|
ng@lycaus.plusYOURSHIT.com (Dariusz) schrieb:
> In article <bpto91.1fg.1@usenet.esken.de>, Matthias Esken <netzkontrolle-nospam@usenetverwaltung.org> wrote: >> ng@lycaus.plusYOURSHIT.com (Dariusz) schrieb: > >>> ++PHP++ >> <? >> echo ("The result is {$_POST['album']}"); >> ?> >> >> or better >> >> <?php >> if (isset($_POST['album'])) { >> echo ('The result is: ' . $_POST['album']); >> } >> ?> >> >> Compare your code and my code and try to find out what you've done >> wrong. If you really can't figure it out and need more explanations feel >> free to ask again. > > Well, as you bring it up, what is the difference between the first PHP code > and the second? Which is better to use? Why? etc... If you call the php script without posting a value for 'album' it will throw a warning in the first case. Then it will assume, that $_POST['album'] might be an empty string (or maybe a number with the value 0), create the variable $_POST['album'] and output the data. You rely on the interpreters guess, what you really wanted to do. In the second case the script checks if it received a value and will not output anything if there was no value. Regards, Matthias |
![]() |
| Thread Tools | |
| Display Modes | |
|
|