By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
429,022 Members | 856 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 429,022 IT Pros & Developers. It's quick & easy.

Forms, post and register_globals

P: n/a
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');

?>
Jul 17 '05 #1
Share this Question
Share on Google+
5 Replies


P: n/a
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 - sp**@koivi.com
PHP POSTERS: Please use comp.lang.php for PHP related questions,
alt.php* groups are not recommended.

Jul 17 '05 #2

P: n/a
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
Jul 17 '05 #3

P: n/a
In article <jv*****************@news7.onvoy.net>, Justin Koivisto <sp**@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
Jul 17 '05 #4

P: n/a
In article <bp**********@usenet.esken.de>, Matthias Esken <ne******************@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
Jul 17 '05 #5

P: n/a
ng@lycaus.plusYOURSHIT.com (Dariusz) schrieb:
In article <bp**********@usenet.esken.de>, Matthias Esken <ne******************@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
Jul 17 '05 #6

This discussion thread is closed

Replies have been disabled for this discussion.