following radio & hidden does not work….. help please. – PHP

  php

Q(Question):

using the following code with a problem….

echo "<input type=’hidden’ name=’member_id’ value=\"{$row[0]}\">{$row[0]}";

echo "<input type=’radio’ name=’member_name’
value=\"{$row[1]}\">{$row[1]}<br />";

The post_data.php program posts the following

member id is: 0009
member_name is: Ralph Jones
cccb_name is: Annexation Committee

Everything is ok but the member id. The number listed ‘0009’ is the
number of the last name in the returned result. It is NOT the number
listed with Ralph Jones which is ‘0007’.

This works the same with a radio button or a select statement.
Any help will be appreciated.

A(Answer):

dba wrote:

using the following code with a problem….

echo "<input type=’hidden’ name=’member_id’
value=\"{$row[0]}\">{$row[0]}";
echo "<input type=’radio’ name=’member_name’
value=\"{$row[1]}\">{$row[1]}<br />";

The post_data.php program posts the following

member id is: 0009
member_name is: Ralph Jones
cccb_name is: Annexation Committee

Everything is ok but the member id. The number listed ‘0009’ is the
number of the last name in the returned result. It is NOT the number
listed with Ralph Jones which is ‘0007’.

This works the same with a radio button or a select statement.
Any help will be appreciated.

I’m terribly sorry, my crystal ball is in the workshop. Maybe someone else’s
crystal ball is working and they can see your code which produces this.

A(Answer):

On Fri, 30 May 2008 23:45:47 +0200, Paul Lautman
<pa**********@btinternet.comwrote:

dba wrote:

>using the following code with a problem….

echo "<input type=’hidden’ name=’member_id’
value=\"{$row[0]}\">{$row[0]}";
echo "<input type=’radio’ name=’member_name’
value=\"{$row[1]}\">{$row[1]}<br />";

The post_data.php program posts the following

member id is: 0009
member_name is: Ralph Jones
cccb_name is: Annexation Committee

Everything is ok but the member id. The number listed ‘0009’ is the
number of the last name in the returned result. It is NOT the number
listed with Ralph Jones which is ‘0007’.

This works the same with a radio button or a select statement.
Any help will be appreciated.

I’m terribly sorry, my crystal ball is in the workshop. Maybe someone
else’s
crystal ball is working and they can see your code which produces this..

Ah, I was wondering why I didn’t see the original post… Plonked because
of <news://48**********************@roadrunner.com>. Ah well, something
less to do for me 🙂

Rik Wasmus
….spamrun finished

A(Answer):

On Fri, 30 May 2008 23:45:47 +0200, Paul Lautman
<pa**********@btinternet.comwrote:

dba wrote:

>using the following code with a problem….

echo "<input type=’hidden’ name=’member_id’
value=\"{$row[0]}\">{$row[0]}";
echo "<input type=’radio’ name=’member_name’
value=\"{$row[1]}\">{$row[1]}<br />";

The post_data.php program posts the following

member id is: 0009
member_name is: Ralph Jones
cccb_name is: Annexation Committee

Everything is ok but the member id. The number listed ‘0009’ is the
number of the last name in the returned result. It is NOT the number
listed with Ralph Jones which is ‘0007’.

This works the same with a radio button or a select statement.
Any help will be appreciated.

I’m terribly sorry, my crystal ball is in the workshop. Maybe someone
else’s
crystal ball is working and they can see your code which produces this..

Hmmm, reading the original post, doing some crystal balling, the OP
doesn’t get what the difference between hidden inputs & radio’s are.
Default UA behvior is to send the last value of an hidden input with the
same name, and only the selected radio button. One cannot expect a
different hidden input to be sent just solely based on a different radio
being selected.

Damn you Paul, for bringing a nicely plonked post to my attention, and
damn me for the addiction to still need to answer it… That’s it, no more
usenet for me today, a beer & a movie it is.

Rik Wasmus
….spamrun finished

A(Answer):

Do not understand your reply. Default UA behavior? is to send the last value of a hidden input with
the same name? and only the selected radio button?

The code is working fine with the following exception. The query is bring back member_id
member_fname and member_lname. The query concatenates the fname and lname but I also need the
member_id with the (radio button or select statement). I was trying to get the member_id using the
hidden input but can not get it to work.

Rik Wasmus wrote:

On Fri, 30 May 2008 23:45:47 +0200, Paul Lautman
<pa**********@btinternet.comwrote:

>dba wrote:

>>using the following code with a problem….

echo "<input type=’hidden’ name=’member_id’
value=\"{$row[0]}\">{$row[0]}";
echo "<input type=’radio’ name=’member_name’
value=\"{$row[1]}\">{$row[1]}<br />";

The post_data.php program posts the following

member id is: 0009
member_name is: Ralph Jones
cccb_name is: Annexation Committee

Everything is ok but the member id. The number listed ‘0009’ is the
number of the last name in the returned result. It is NOT the number
listed with Ralph Jones which is ‘0007’.

This works the same with a radio button or a select statement.
Any help will be appreciated.

I’m terribly sorry, my crystal ball is in the workshop. Maybe someone
else’s
crystal ball is working and they can see your code which produces this.

Hmmm, reading the original post, doing some crystal balling, the OP
doesn’t get what the difference between hidden inputs & radio’s are.
Default UA behvior is to send the last value of an hidden input with the
same name, and only the selected radio button. One cannot expect a
different hidden input to be sent just solely based on a different radio
being selected.

Damn you Paul, for bringing a nicely plonked post to my attention, and
damn me for the addiction to still need to answer it… That’s it, no
more usenet for me today, a beer & a movie it is.

A(Answer):

On Fri, 30 May 2008 20:00:51 -0500, dba wrote:

Do not understand your reply. Default UA behavior? is to send the last
value of a hidden input with the same name? and only the selected
radio button?

In short, it’s an HTML problem. Essentially, if you send of a form

<input type="hidden" name="my_field" value="1">
<input type="hidden" name="my_field" value="2">
<input type="hidden" name="my_field" value="3">

your $_POST results will show my_field == 3. Even interlacing a radio
button set with those like

<input type="radio" name="my_set" value="1">
<input type="hidden" name="my_field" value="1">
<input type="radio" name="my_set" value="2">
<input type="hidden" name="my_field" value="2">
<input type="radio" name="my_set" value="3">
<input type="hidden" name="my_field" value="3">

will have absolutely no effect on the valye of my_field, because there
is no way to really associate the hidden inputs with the radio inputs.
They’re entirely separate controls.

There’s two ways to resolve this: an html way and a php way. The html
way is to make each of the hidden fields DIFFERENT from the others, like

<input type="hidden" name="my_field_set1" value="1">
<input type="hidden" name="my_field_set2" value="2">
<input type="hidden" name="my_field_set3" value="3">

which then becomes

<input type="radio" name="my_set" value="1">
<input type="hidden" name="my_field_set1" value="1">
<input type="radio" name="my_set" value="2">
<input type="hidden" name="my_field_set2" value="2">
<input type="radio" name="my_set" value="3">
<input type="hidden" name="my_field_set3" value="3">

when you interlace, and you make your form processor look at the value
of my_field_set1, my_field_set2, or my_field_set3 depending on the value
of my_set.

The php way is that instead of sending out the hidden fields at all, you
save them in the session data, then pull them back out when the form is
processed, based on the value of my_set, almost exactly like the last
part of the html method. This way of doing things is probably better,
all things otherwise being equal, because it prevents the value of your
hidden field from being seen, corrupted, or otherwise invalid.

The code is working fine with the following exception. The query
is bring back member_id member_fname and member_lname. The query
concatenates the fname and lname but I also need the member_id with
the (radio button or select statement). I was trying to get the
member_id using the hidden input but can not get it to work.

The query’s fine, What you’re missing is a bit of understanding of how
THE BROWSER (the UA — user agent) manages form data. Which is why it’s
an HTML question in the first place.


52. I will hire a team of board-certified architects and surveyors to
examine my castle and inform me of any secret passages and abandoned
tunnels that I might not know about.
–Peter Anspach’s list of things to do as an Evil Overlord

A(Answer):

Mr. Coffin,

Thank you for a great answer and some fine pointers. Will be trying some of your
ideas immediately.

Again, thank you very much.
Peter H. Coffin wrote:

On Fri, 30 May 2008 20:00:51 -0500, dba wrote:

>Do not understand your reply. Default UA behavior? is to send the last
value of a hidden input with the same name? and only the selected
radio button?

In short, it’s an HTML problem. Essentially, if you send of a form

<input type="hidden" name="my_field" value="1">
<input type="hidden" name="my_field" value="2">
<input type="hidden" name="my_field" value="3">

your $_POST results will show my_field == 3. Even interlacing a radio
button set with those like

<input type="radio" name="my_set" value="1">
<input type="hidden" name="my_field" value="1">
<input type="radio" name="my_set" value="2">
<input type="hidden" name="my_field" value="2">
<input type="radio" name="my_set" value="3">
<input type="hidden" name="my_field" value="3">

will have absolutely no effect on the valye of my_field, because there
is no way to really associate the hidden inputs with the radio inputs.
They’re entirely separate controls.

There’s two ways to resolve this: an html way and a php way. The html
way is to make each of the hidden fields DIFFERENT from the others, like

<input type="hidden" name="my_field_set1" value="1">
<input type="hidden" name="my_field_set2" value="2">
<input type="hidden" name="my_field_set3" value="3">

which then becomes

<input type="radio" name="my_set" value="1">
<input type="hidden" name="my_field_set1" value="1">
<input type="radio" name="my_set" value="2">
<input type="hidden" name="my_field_set2" value="2">
<input type="radio" name="my_set" value="3">
<input type="hidden" name="my_field_set3" value="3">

when you interlace, and you make your form processor look at the value
of my_field_set1, my_field_set2, or my_field_set3 depending on the value
of my_set.

The php way is that instead of sending out the hidden fields at all, you
save them in the session data, then pull them back out when the form is
processed, based on the value of my_set, almost exactly like the last
part of the html method. This way of doing things is probably better,
all things otherwise being equal, because it prevents the value of your
hidden field from being seen, corrupted, or otherwise invalid.

>The code is working fine with the following exception. The query
is bring back member_id member_fname and member_lname. The query
concatenates the fname and lname but I also need the member_id with
the (radio button or select statement). I was trying to get the
member_id using the hidden input but can not get it to work.

The query’s fine, What you’re missing is a bit of understanding of how
THE BROWSER (the UA — user agent) manages form data. Which is why it’s
an HTML question in the first place.

LEAVE A COMMENT