I have a page to edit inforation in a mysql database. It's pretty simple, fields that consit of location name, address, city, state and zip. I have a combo box for state that populates from a query. The states table have 3 columns, ID, statename and stateabbr (aberivations). In the location table, I have a field called stateid which is joined with state table. When using the edit record, it pull up the current info that is stored in the database. Here is the code:

echo "<tr><td>State:</td><td><select name=\"stateid\"><option selected=\"yes\"><value=\"" .$row['stateid']. "\">" .$row[statename]. "</option>";

When I view source, it displays this

<tr><td>State:</td><td><select name="stateid"><option selected="yes"><value="5">CALIFORNIA </option><option value="1">ALABAMA</option><option value="2">ALASKA</option> etc., etc., etc.

When I click the submit, the post value is the statename and not the value shown in the view source. What is causing that? If I modify the state, it works.

    I admin I'm confused.

    If you setup your code as follows:

    
    <select name="select">
    <option value="1">Arizona</option>
    <option value="2">California</option>
    <option value="3">Nevada</option>
    </select>
    
    

    You will get back your select value as 1, 2 or 3.

    The one problem I saw in your examples was in CALIFORNIA

    
    <option selected="yes"><value="5">CALIFORNIA </option>
    
    

    I've never seen a value brought out into it's own tag... could that be the problem?

      DOH! I found where the problem was, I had it like

      <option selected="yes"><value="5">CALIFORNIA </option>
      

      and changing it to

      <option selected="yes" value="5">CALIFORNIA </option>
      

      fixed it.

      Thanks for the help!

        Don't forget to mark this resolved please.

          Write a Reply...