Forms, post and register_globals

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


Go Back   Usenet Forums > PHP Programming Forums > PHP Language

FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 11-24-2003
Dariusz
 
Posts: n/a
Default Forms, post and register_globals

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');

?>
Reply With Quote
  #2 (permalink)  
Old 11-24-2003
Justin Koivisto
 
Posts: n/a
Default Re: Forms, post and register_globals

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.

Reply With Quote
  #3 (permalink)  
Old 11-24-2003
Matthias Esken
 
Posts: n/a
Default Re: Forms, post and register_globals

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
Reply With Quote
  #4 (permalink)  
Old 11-26-2003
Dariusz
 
Posts: n/a
Default Re: Forms, post and register_globals

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
Reply With Quote
  #5 (permalink)  
Old 11-26-2003
Dariusz
 
Posts: n/a
Default Re: Forms, post and register_globals

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
Reply With Quote
  #6 (permalink)  
Old 11-26-2003
Matthias Esken
 
Posts: n/a
Default Re: Forms, post and register_globals

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
Reply With Quote
Reply


Thread Tools
Display Modes

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

vB code is On
Smilies are Off
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT +1. The time now is 11:58 PM.


Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO 3.0.0