Page 1 of 1

Dynamic "value" in HTML form with PHP

Posted: Fri Mar 06, 2009 2:20 pm
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

Re: Dynamic "value" in HTML form with PHP

Posted: Fri Mar 06, 2009 2:45 pm
by Benjamin
That would be the primaryKey for the table the record came from.

Re: Dynamic "value" in HTML form with PHP

Posted: Fri Mar 06, 2009 5:55 pm
by bradsssp
OK, that is the piece of information i would use but, how do i assign that as a "value" in the form?

Re: Dynamic "value" in HTML form with PHP

Posted: Sat Mar 07, 2009 3:23 am
by BomBas
What are your columns?

I think the value should be $id (if you got this column..)

Re: Dynamic "value" in HTML form with PHP

Posted: Sat Mar 07, 2009 11:50 am
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>