Dynamic "value" in HTML form with PHP

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
bradsssp
Forum Newbie
Posts: 3
Joined: Fri Mar 06, 2009 2:01 pm

Dynamic "value" in HTML form with PHP

Post by bradsssp »

I am creating a page where you can select an existing user from a drop down box and then edit that users information(username, password, email etc...). I currently have the drop down box that prints the users first and last name in as "options" in the menu. I am running into issues assigning a "value" to each option that actually represents the "option" that was chosen. Am i going about this wrong? help please.
<?php
while ($rows = mysql_fetch_array($result)) //extracts the results of the mysql query
{
extract($rows);
?>
<option value="VARIABLE TO CORRELATE TO THE RECORD PRINTED "><?php echo "$lastname, $firstname"; ?></option>
<?php
}//closes while loop
?>
</select>
<html>
<head>
</head>
<body>
<form action="edituser.php" method="post">
<input type="submit" name="edit" value="Edit User">
</form>
</body>
</html>
<?php
User avatar
Benjamin
Site Administrator
Posts: 6935
Joined: Sun May 19, 2002 10:24 pm

Re: Dynamic "value" in HTML form with PHP

Post by Benjamin »

That would be the primaryKey for the table the record came from.
bradsssp
Forum Newbie
Posts: 3
Joined: Fri Mar 06, 2009 2:01 pm

Re: Dynamic "value" in HTML form with PHP

Post by bradsssp »

OK, that is the piece of information i would use but, how do i assign that as a "value" in the form?
BomBas
Forum Commoner
Posts: 41
Joined: Wed Mar 04, 2009 1:04 pm

Re: Dynamic "value" in HTML form with PHP

Post by BomBas »

What are your columns?

I think the value should be $id (if you got this column..)
bradsssp
Forum Newbie
Posts: 3
Joined: Fri Mar 06, 2009 2:01 pm

Re: Dynamic "value" in HTML form with PHP

Post by bradsssp »

Let me reword my question. I'm having problems with the syntax to assign the value from my database to the "value" field of the drop down box form.
ex.

Code: Select all

<option value="[color=#FF0000]PHP SYNTAX FOR THIS VALUE[/color]"><?php echo "$lastname, $firstname"; ?></option>
Post Reply