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!
I have an html form for contact data displays a drop down for state. The rows for the states are loaded in another table (state). When I use the following code to insert a new row, it works just fine.
My problem is when I use this to "update" on another window, the state is updated with the first row of data from the state table. How do I get the form variable to display the value that's currently on the contact row?
<td><b>State:</b></td>
<td><select name="state_abbr">
<?php
$statelink = mysql_connect('localhost', 'id', 'pwd');
//the database that will be used
mysql_select_db('db') or die('An error as occurred.');
$statequery = 'SELECT abbr,name FROM state ORDER BY abbr';
$stateresult = mysql_query($statequery, $statelink);
while($staterow = mysql_fetch_array($stateresult, MYSQL_ASSOC))
{
$statelevel = $staterow['abbr'];
$statename = $staterow['name'];
// $state_abbr is the current state value for the row being displayed/updated.
if($statelevel == $state_abbr)
{
print("<option value=$statelevel SELECTED>$statelevel - $statename</option>");
}
else
{
print ("<option value=$statelevel>$statelevel - $statename</option>");
}
}
?>
</select>
</td>
On to the next challenge...
rodan
Last edited by rodan on Sun Apr 11, 2010 12:37 pm, edited 2 times in total.
[ /syntax] tags when posting code blocks in the forums. Your code will be syntax highlighted making it much easier for everyone to read. You will most likely receive more answers as well.
If you are new to the forums, please be sure to read:
[list=1][*][url=http://forums.devnetwork.net/viewtopic.php?t=30037]Forum Rules[/url]
[*][url=http://forums.devnetwork.net/viewtopic.php?t=8815]General Posting Guidelines[/url]
[*][url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url][/list]