Jump to content

SQL PHP echo for dropdowns


WAMFT1

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
https://forums.phpfreaks.com/topic/281655-sql-php-echo-for-dropdowns/
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>

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.