Forum Moderators: coopster

Message Too Old, No Replies

Selection dropdown list

Can't get it working

         

pixeldiver

6:21 am on Aug 20, 2009 (gmt 0)

10+ Year Member



Hi all,
I can't get my code working. I have two selection dropdown boxes and one submit button. Users should be able to select from either one or both boxes and hit submit which then should grab the products in the database and displays it.

This should be pretty basic BUT, I'm doing something wrong.
Any help would be appresciated.

<form method="POST" action="<?php echo $_SERVER['PHP_SELF']; ?>">
<table width="979" border="0" align="left" cellpadding="0" cellspacing="0" id="table_step1">
<tr align="left" valign="bottom">
<td width="111" align="left" valign="middle">Air Direction</td>
<td width="262" align="left" valign="top"><select name="step1[]" size="1" ><option value="" selected="selected">Please select ...</option>
<option value="supply">SUPPLY</option>
<option value="return">RETURN</option>
<option value="exhaust">EXHAUST</option>
<option value="relief">RELIEF AIR</option>
</select></td>
<td width="126" align="left" valign="middle">Installation Type</td>
<td width="287" align="left" valign="top"><select name="step1[]" size="1">
<option value="" selected="selected">Please select ...</option>
<option value="aircon">AIR CONDITIONING</option>
<option value="ceiling">CEILING</option>
<option value="diffuser">DIFFUSER</option>
<option value="door">DOOR</option>
<option value="duct">DUCT</option>
<option value="exterior">EXTERIOR WALL</option>
<option value="floor">FLOOR</option>
<option value="grille">GRILLE</option>
<option value="register">REGISTER</option>
<option value="wall">WALL</option>
<option value="window">WINDOW SILL</option>
</select></td>
<td width="193" align="left" valign="bottom"><input name="submitstep1" type="submit" value="Submit" /><input type="hidden" name="step1" id="step1" value="" /></td>
</tr>
</table>
</form>

**********Output here*********

<?php mysql_select_db($database_dragon, $dragon);
$query = "SELECT img_src, air_direction, installation FROM products WHERE air_direction LIKE '%{$a}%' AND installation LIKE '%{$a}%' ";
$result = mysql_query($query, $dragon) or die(mysql_error());
$totalRows = mysql_num_rows($result);

while ($row = mysql_fetch_assoc($result)) {

echo $row['img_src'];} ?>

mikeyb

9:47 am on Aug 20, 2009 (gmt 0)

10+ Year Member



Both your selects have the same name name="step1[]"

I'm not even sure [] will be valid anyway.

You also have a hidden field called step1.

Each input field on a form should have a unique name/id.

pixeldiver

9:55 pm on Aug 20, 2009 (gmt 0)

10+ Year Member



Thanks mikeyb, I have changed the names and took out []. That works fine.
My other problem is that when the page loads it shows the all data (results) from the database without having clicked submit. The results section (output) should be empty when the page loads. And it should display data only when selection has been made and submitted.

Any ideas?