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

problem with php + form + input type = "hidden"

P: n/a
dba
Without giving a lot of script at this time, I am having a problem with
php and form input type="hidden". Problem is that the hidden variable
displays last line from database query.

Some code.
if ($field_name=="member_lname") {
echo "<input type='radio' name='selection' value=' " .
$result['member_lname']. ',' .$result['member_fname'] ." ' " .
$result['member_lname'] . ', ' . $result['member_fname'] . "<br />";
echo "<input type='hidden' name='member_id' value=" .
$result['member_id'] . " ' >" . $result['member_id'] . " />" ; }

produces this from form:
Back, Joe 0026
Clan, Bill 0025
Dant, Norbert 0020
Cleene, Nor 0013
De Wa, Frank 0012
Erick, B.C. 0006
Evans, Mary 0027
Far, Steve 0005

after selection from form $_POST produces
correct name "Dant, Norbert" but grabs last number "0005" and not "0020".

Any help would be appreciated.
Oct 17 '07 #1
Share this Question
Share on Google+
3 Replies


P: n/a
dba
My output is as follows:

************************************************** *******************************************
you entered display1.php

Array ( [cccb_id] =00007 [selection] =00008Executive Committee )

selection is: 00008Executive Committee
member_id is: cccb_id is: 00007

************************************************** ********************************************

Now, as you can see from the about output, the array cccb_id indicates
00007 while I also get 00008 which is correct. The 00007 is the last row
selected from the database. The name of the committee "Executive
Committee" is correct. So part of the data being returned is correct by
part is not. The part that is not is the 'input type="hidden" as
indicated in the initial thread.

Also, I appreciate critical remarks about my code but would like an
explanation. If I was sloppy enough to make the mistake I probably did
not know it was sloppy or why it was sloppy. Please elaborate.

Gary L. Burnore wrote:
On Wed, 17 Oct 2007 01:19:43 GMT, dba <db*@somewhere.orgwrote:

>>Without giving a lot of script at this time, I am having a problem with
php and form input type="hidden". Problem is that the hidden variable
displays last line from database query.

Some code.
if ($field_name=="member_lname") {
echo "<input type='radio' name='selection' value=' " .
$result['member_lname']. ',' .$result['member_fname'] ." ' " .
$result['member_lname'] . ', ' . $result['member_fname'] . "<br />";


>>echo "<input type='hidden' name='member_id' value=" .
$result['member_id'] . " ' >" . $result['member_id'] . " />" ; }


This would return:

<input type='hidden' name='member_id' value=NNNN ' NNNNN />

Bet that's not what you want.

Oh, and ; } is sloppy programming.

>>produces this from form:
Back, Joe 0026
Clan, Bill 0025
Dant, Norbert 0020
Cleene, Nor 0013
De Wa, Frank 0012
Erick, B.C. 0006
Evans, Mary 0027
Far, Steve 0005

after selection from form $_POST produces
correct name "Dant, Norbert" but grabs last number "0005" and not "0020".

Any help would be appreciated.
Oct 17 '07 #2

P: n/a
Greetings, dba.
In reply to Your message dated 17 2007 ., 05:19:43,

dWithout giving a lot of script at this time, I am having a problem with
dphp and form input type="hidden". Problem is that the hidden variable
ddisplays last line from database query.

dSome code.
[snip]

dproduces this from form:
[snip]

dafter selection from form $_POST produces
dcorrect name "Dant, Norbert" but grabs last number "0005" and not "0020".

First, to lower chance of messing with output, use templates.
Second... Don't forget to escape output.

That way, Your code may looks like this

<?php

if ($field_name=="member_lname")
{
$_name = htmlspecialchars($result['member_lname'] . ', ' . $result['member_fname']);
$_id = $result['member_id'];
echo "<input type='radio' name='selection' value='{$_name}'/>$_name<br />";
echo "<input type='hidden' name='member_id' value='{$_id}'/>";
}

?>

Good luck with this code :)

P.S.
Aside from that, I think You would be better with
echo "<input type='radio' name='selection' value='{$_id}'/>$_name<br />";
--
Sincerely Yours, AnrDaemon <an*******@freemail.ru>

Oct 17 '07 #3

P: n/a
dba
AnrDaemon,

Thanks for the suggestions. Have been planning on looking into templates
at some time in the future and will do so.

AnrDaemon wrote:
Greetings, dba.
In reply to Your message dated 17 2007 ., 05:19:43,

dWithout giving a lot of script at this time, I am having a problem with
dphp and form input type="hidden". Problem is that the hidden variable
ddisplays last line from database query.

dSome code.
[snip]

dproduces this from form:
[snip]

dafter selection from form $_POST produces
dcorrect name "Dant, Norbert" but grabs last number "0005" and not "0020".

First, to lower chance of messing with output, use templates.
Second... Don't forget to escape output.

That way, Your code may looks like this

<?php

if ($field_name=="member_lname")
{
$_name = htmlspecialchars($result['member_lname'] . ', ' . $result['member_fname']);
$_id = $result['member_id'];
echo "<input type='radio' name='selection' value='{$_name}'/>$_name<br />";
echo "<input type='hidden' name='member_id' value='{$_id}'/>";
}

?>

Good luck with this code :)

P.S.
Aside from that, I think You would be better with
echo "<input type='radio' name='selection' value='{$_id}'/>$_name<br />";

Oct 17 '07 #4

This discussion thread is closed

Replies have been disabled for this discussion.