Grab data and use it in Select field on form

I’m really stuck with this, i know it’s probably one of the easiest things to get working but i’m left scratching my head with this one…

I’ve got a form that lets me edit a row in a database table.

The thing is, one part of the form is a select rather than an input box. At the moment i’m having to select the correct bit of data from the pull down everytime i want to edit a row. If i don’t do this it updates the database with an empty selection.

The data from the table is being pulled because when i do an echo on the edit page i can see the bit of data i need. It’s just getting this into the select

The variable is called $breaker_manufacturer and here is the select as it is currently setup… Obviously i need to edit the bit between the <?php ?>, it’s just what do i put there?

Thanks very much.


<tr><td class="edit_odd"align="left">Manufacturer:</td>  
	<td align="left"><select name="breaker_manufacturer">
    <option value="" <?php if(!$_POST['manufacturer']) echo ' selected="selected"' ?>/>
  	<option value="All" <?php if($_POST['manufacturer']=="All") echo ' selected="selected"' ?>/>All
    <option value="Classic" <?php if($_POST['manufacturer']=="Classic") echo ' selected="selected"' ?>/>Classic
	<option value="" <?php if(!$_POST['manufacturer']) echo ' selected="selected"' ?>/>

    <option value="Aprilia" <?php if($_POST['manufacturer']=="Aprilia") echo ' selected="selected"' ?>/>Aprilia
    <option value="Benelli"  <?php if($_POST['manufacturer']=="Benelli") echo ' selected="selected"' ?>/>Benelli
		<option value="Beta"  <?php if($_POST['manufacturer']=="Beta") echo ' selected="selected"' ?>/>Beta
		<option value="Bimota"  <?php if($_POST['manufacturer']=="Bimota") echo ' selected="selected"' ?>/>Bimota
		<option value="BMW"  <?php if($_POST['manufacturer']=="BMW") echo ' selected="selected"' ?>/>BMW
		<option value="BSA"  <?php if($_POST['manufacturer']=="BSA") echo ' selected="selected"' ?>/>BSA
		<option value="Buell"  <?php if($_POST['manufacturer']=="Buell") echo ' selected="selected"' ?>/>Buell
		<option value="Cagiva"  <?php if($_POST['manufacturer']=="Cagiva") echo ' selected="selected"' ?>/>Cagiva
		<option value="CCM"  <?php if($_POST['manufacturer']=="CCM") echo ' selected="selected"' ?>/>CCM
		<option value="Derbi"  <?php if($_POST['manufacturer']=="Derbi") echo ' selected="selected"' ?>/>Derbi
		<option value="Ducati"  <?php if($_POST['manufacturer']=="Ducati") echo ' selected="selected"' ?>/>Duati
		<option value="Enfield"  <?php if($_POST['manufacturer']=="Enfield") echo ' selected="selected"' ?>/>Enfield
		<option value="Gillera"  <?php if($_POST['manufacturer']=="Gillera") echo ' selected="selected"' ?>/>Gillera
		<option value="Harley-Davidson"  <?php if($_POST['manufacturer']=="Harley-Davidson") echo ' selected="selected"' ?>/>Harley-Davidson
		<option value="Honda"  <?php if($_POST['manufacturer']=="Honda") echo ' selected="selected"' ?>/>Honda
		<option value="Husqvarna"  <?php if($_POST['manufacturer']=="Husqvarna") echo ' selected="selected"' ?>/>Husqvarna
		<option value="Hyosung"   <?php if($_POST['manufacturer']=="Hyosung") echo ' selected="selected"' ?>/>Hyosung
		<option value="Italijet"   <?php if($_POST['manufacturer']=="Italijet") echo ' selected="selected"' ?>/>Italijet
		<option value="Kawasaki"   <?php if($_POST['manufacturer']=="Kawasaki") echo ' selected="selected"' ?>/>Kawasaki
		<option value="Kymco"   <?php if($_POST['manufacturer']=="Kymco") echo ' selected="selected"' ?>/>Kymco
		<option value="Laverda"   <?php if($_POST['manufacturer']=="Husqvarna") echo ' selected="selected"' ?>/>Laverda
		<option value="Moto Guzzi"   <?php if($_POST['manufacturer']=="Moto Guzzi") echo ' selected="selected"' ?>/>Moto Guzzi
		<option value="MV Agusta"   <?php if($_POST['manufacturer']=="MV Agusta") echo ' selected="selected"' ?>/>MV Agusta
		<option value="MZ"   <?php if($_POST['manufacturer']=="MZ") echo ' selected="selected"' ?>/>MZ
		<option value="Norton"   <?php if($_POST['manufacturer']=="Norton") echo ' selected="selected"' ?>/>Norton
		<option value="NRG" <?php if($_POST['manufacturer']=="NRG") echo ' selected="selected"' ?>/>NRG
		<option value="Peugeot"   <?php if($_POST['manufacturer']=="Peugeot") echo ' selected="selected"' ?>/>Peugeot
		<option value="Sachs"   <?php if($_POST['manufacturer']=="Sachs") echo ' selected="selected"' ?>/>Sachs
		<option value="Suzuki"   <?php if($_POST['manufacturer']=="Suzuki") echo ' selected="selected"' ?>/>Suzuki
		<option value="Triumph"   <?php if($_POST['manufacturer']=="Triumph") echo ' selected="selected"' ?>/>Triumph
		<option value="Vespa"   <?php if($_POST['manufacturer']=="Vespa") echo ' selected="selected"' ?>/>Vespa
		<option value="Yamaha"   <?php if($_POST['manufacturer']=="Yamaha") echo ' selected="selected"' ?>/>Yamaha
	</select></td></tr>

First thing, and maybe I am wrong, but I did look it up…

It should be

Name

Not:

Name

After rendering the page in the browser to a view source on it and see what that looks like compared to what it should be.

Not sure if this well help, but if not let us know and I will take a second look.

u sould use $_POST[‘breaker_manufacturer’] instead of $_POST[‘manufacturer’]

@Ragster00: of cause <option value="yourvalue"/>Name is wrong but <option value="yourvalue">Name (without closing-tag) would be vaild html to. (like
)

That sort of worked, but i did the following…

[php]

/>Beta [/php]

And it is working! :D

Sponsor our Newsletter | Privacy Policy | Terms of Service