Page 1 of 1

list box wont store variables

Posted: Tue Aug 28, 2007 1:25 pm
by SirChick
I have a list box which loads up data from database as shown below:

Code: Select all

<?php
$soldhousesquery = "SELECT Price, HouseType FROM soldhouses ORDER BY Price ASC";
$soldhousesresult = @mysql_query($soldhousesquery) or die(mysql_error());


echo '<select name="BuyCombo" size="6" id="Combobox3" style="position:absolute;left:343px;top:450px;width:223px;font-family:MS Shell Dlg;z-index:25">';

while($soldhousesrow = mysql_fetch_array($soldhousesresult)) {
        echo "<option value=\"{$soldhousesrow['Price']}|{$soldhousesrow['HouseType']}\">£ {$soldhousesrow['Price']} - {$soldhousesrow['HouseType']}</option>";
}

echo '</select>';
echo '<input type="submit" />';
echo '</form>';

?>
What happens then is the user selects one of the options and presses "buy" upon buy being pressed the selected choice should be bought, how ever i cannot get it to assign it to variables.

I have attempted here:
process page:

Code: Select all

$value = $_POST['houselist'];
  $posistion = strpos($value, '|');
  if ($posistion !== false)
  {
    $HousePrice = substr($value, 0, $posistion);
    $HouseType = substr($value, $posistion+1);
  }
When i echoed $HousePrice and $HouseType the result was blank. Any one see where i gone wrong?

Posted: Tue Aug 28, 2007 1:28 pm
by TheMoose
Check your form element names against what you're trying to get with $_POST. Hint: they're not the same.

Posted: Tue Aug 28, 2007 1:34 pm
by SirChick
Do you mean that:

$_POST['houselist']

should be

$_POST['buycombo']

Posted: Tue Aug 28, 2007 3:56 pm
by TheMoose
SirChick wrote:Do you mean that:

$_POST['houselist']

should be

$_POST['buycombo']
Yep :)