Jump to content

SQL PHP echo for dropdowns


WAMFT1
Go to solution Solved by PaulRyan,

Recommended Posts

I have a created a "state" dropdown box on a form which enters into the SQL, when I php echo it shows the state ok as text but when I try to get it to populate on the edit screen within the dropdown box it does not show.

 

I am trying to get the dropdown box to automatically select the state from the data in SQL. Where am I going wrong with this.  

 

Any help would be appreciated.

<select name="State" id="State" selected="<?php echo $State ?>">
            <option value="--">--</option>
            <option value="ACT">ACT</option>
            <option value="NSW">NSW</option>
            <option value="NT">NT</option>
            <option value="QLD">QLD</option>
            <option value="SA">SA</option>
            <option value="TAS">TAS</option>
            <option value="VIC">VIC</option>
            <option value="WA">WA</option>
            </select>
Link to comment
Share on other sites

I changed as you mentioned above and removed the selected from the attribute but it still does not seem to select the dropdown.

<select name="State" id="State">
            <option value="--"<?php ($State == '--') ? ' "selected"' : '';?>>--</option>
            <option value="ACT"<?php ($State == 'ACT') ? ' "selected"' : '';?>>ACT</option>
            <option value="NSW"<?php ($State == 'NSW') ? ' "selected"' : '';?>>NSW</option>
            <option value="NT"<?php ($State == 'NT') ? ' "selected"' : '';?>>NT</option>
            <option value="QLD"<?php ($State == 'QLD') ? ' "selected"' : '';?>>QLD</option>
            <option value="SA"<?php ($State == 'SA') ? ' "selected"' : '';?>>SA</option>
            <option value="TAS"<?php ($State == 'TAS') ? ' "selected"' : '';?>>TAS</option>
            <option value="VIC"<?php ($State == 'VIC') ? ' "selected"' : '';?>>VIC</option>
            <option value="WA"<?php ($State == 'WA') ? ' "selected"' : '';?>>WA</option>
            </select>
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.